android - 尝试在项目中使用新的 com.android.test 插件时出错

标签 android android-studio gradle android-gradle-plugin build.gradle

<分区>

我们有一个使用 flavors 的项目,并希望使用 gradle 1.3 提供的新 com.android.test 插件在单独的项目中进行集成测试。我们已按照说明进行操作 here ,但是当我们尝试同步 gradle 时,我们收到以下错误:

Error:Configuration with name 'MyFlavorDebug-classes' not found.

这是我们测试项目的 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
}

关于android - 尝试在项目中使用新的 com.android.test 插件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31815839/

相关文章:

android - Play 商店显示 0 个具有相同代码的受支持设备

android - packageDebug 和 assembleDebug 之间的 gradle 区别

android - 如何在 android studio 的 gradle 4.4 中发布 Artifact (将 APK 上传到 nexus)?

android - 如何在 Android 1.5 的应用程序同步设置配置屏幕中列出我的应用程序?

android-studio - Android studio 4.1 构建失败

java - 在 MapFragment 中调用 onRequestPermissionResult 时出现 Android Studio @androidx.annotation.NonNull 错误

android - 删除导航菜单中的大间隙

java - 无法从转换 View 获取父位置

android - SDL 构建系统 - 当我链接到 `gnuSTL_shared` 时,我在运行时得到 "Error: Cannot load library: ..."

android - android.hardware.camera2.CaptureRequest 可以与 OpenCV 一起使用吗?