在Android Studio中使用testCompile出现依赖项无法解析的问题

4

我有一些测试放在MainProject/Project/src/test中。我正在使用Jake Wharton的gradle-android-test-plugin。每当我用testCompile指定一个依赖项时,它不会在IDE中自动完成。但是它确实编译了。

我的build.gradle文件看起来像这样:

buildscript {
    repositories {
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
        classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'

    }
}
apply plugin: 'android'
apply plugin: 'android-test'


repositories {
    mavenCentral()
}

dependencies {

    testCompile 'junit:junit:4.11'

}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"
}

但是每当我尝试编码时,它就会出现这种情况:

enter image description here

这很烦人,降低了我的生产力。有什么建议可以解决这个问题吗?谢谢。

1个回答

7

我也遇到了同样的问题。我的临时解决方案是在instrumentTestCompile中重复testCompile的dependencies。

这样,Android Studio就能识别instrumentTestCompile的dependencies并开始自动完成了。


11
现在应该使用androidTestCompile而不是instrumentTestCompile(很可能是从Android Gradle插件版本0.9.0开始)。 - losttime
又坏了,在Android Studio 1.4上出问题了。 - Andrey Starodubtsev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接