Android studio 1.1.0无法设置Robolectric

时间:2015-04-18 08:18:47

标签: android unit-testing robolectric

我在Android 1.1.0之前使用过Robolectric,但在更新之后我再也无法使用它了。我用Google搜索并尝试了一些解决方案,但没有一个有效。 这是我目前的设置:

project.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

app.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "my_package_name"
        minSdkVersion 9
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

apply plugin: 'android-unit-test'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:recyclerview-v7:21.0.3'
    testCompile 'org.easytesting:fest:1.0.16'
    testCompile 'junit:junit:4.10'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'com.squareup:fest-android:1.0.8'
}

当我尝试构建项目时,它给出了如下错误:

Error:(22) A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'android-unit-test']
   > No such property: bootClasspath for class: com.android.build.gradle.AppPlugin

当然,我安装了android-unit-test插件并重新安装,但没有运气。

您的回答将不胜感激。

1 个答案:

答案 0 :(得分:6)

坏消息:自Android插件1.1.0以来,插件com.github.jcandksolutions.gradle:android-unit-test:2.1.1已被删除。另请参阅https://github.com/JCAndKSolutions/android-unit-test#deprecation-notice

好消息:你不再需要robolectric的插件了。只需删除apply plugin: 'android-unit-test',所有内容都应该像以前一样工作。

这里有一个示例项目设置https://github.com/nenick/AndroidStudioAndRobolectric