This question already has answers here:
Android Test Module (Gradle Plugin 1.3) doesn't work: “debug-classes not found”

(2个答案)


5年前关闭。




我们有一个使用口味的项目,并且希望使用gradle 1.3附带的新com.android.test插件将集成测试放在一个单独的项目中。我们遵循了here的指示,但是当我们尝试同步gradle时,出现以下错误:



这是我们测试项目的build.gradle文件。我们的应用程序具有匹配的风格。
buildscript {

    repositories {
        mavenCentral()
        jcenter()
    }

}

apply plugin: 'com.android.test'


android {

    compileSdkVersion 21
    buildToolsVersion = '22.0.1'
    targetProjectPath ':MyApp'
    targetVariant 'MyFlavorDebug'
}

最佳答案

您应该具有以下结构:

root
 app
   build.gradle
 flavor1test
   build.gradle

app/build.gradle
   android{
       defaultConfig {
           applicationId 'com.example.myapp'

       }
       productFlavors {
            flavor1 {
               //
            }
       }
    }

flavor1test/build.gradle中,如下所示:
apply plugin: 'com.android.test' // A plugin used for test-only-modules

android {
    compileSdkVersion 22
    buildToolsVersion = '23.0.0rc3'

    defaultConfig {
        minSdkVersion XX
        targetSdkVersion 22

        // The package name of the test app
        testApplicationId 'com.example.myapp'

     // The Instrumentation test runner used to run tests.
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }

    // Set the target app project.
    targetProjectPath ':app'
    targetVariant 'flavor1Debug'
}

dependencies {
    // Android Testing Support Library's runner and rules and hamcrest matchers
}

09-10 02:23
查看更多