错误:无法在Robolectric中解析配置':app:testCompile`的所有依赖项

时间:2014-10-01 11:02:19

标签: android unit-testing robolectric robolectric-gradle-plugin

您好我正在编写我的演示Android应用程序的单元测试用例,所以为此我使用robolectric单元框架。当我运行它gradlew test然后它给出错误无法解析配置的所有依赖项':app:testCompile`。请参阅随附的屏幕截图。

以下是我的root build.gradle

的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'

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

allprojects {
    repositories {
        jcenter()
    }
}

我的项目build.grade文件如下所示

apply plugin: 'android'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.xyz.robolectricapplication"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        // this sets the root test folder to src/test overriding the default src/instrumentTest
        instrumentTest.setRoot('src/test')
    }
}

apply plugin: 'android-test'


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.10'
    testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
    testCompile 'com.squareup:fest-android:1.0.+'
    instrumentTestCompile 'junit:junit:4.10'
    instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
    instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}

buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }
    dependencies {
        classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
    }
}

repositories {
    mavenCentral()
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

错误记录

enter image description here

项目结构如下所示

enter image description here

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果您要抓取快照,则需要抓住2.4-SNAPSHOT。

请参阅:https://github.com/robolectric/robolectric/blob/master/pom.xml

所以替换testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'testCompile 'org.robolectric:robolectric:2.4-SNAPSHOT'

或者最好抓住稳定的2.3版本:org.robolectric:robolectric:2.3

这里有一个示例gradle项目,它可能会有所帮助:https://github.com/robolectric/deckard-gradle