使用没有发布变体的 Android 测试插件时避免“变体选择冲突”警告

hb0*_*hb0 6 android android-testing android-studio gradle-android-test-plugi android-gradle-3.0

我想做的事和问题

我将 Android Studio 和 Android Gradle 插件更新为 3.0.1,将 Gradle Wrapper 更新为 4.1,并且可以通过 IDE 在设备上以发行版本构建和部署我的 Android Gradle 项目。

  • 但是,会显示以下“Gradle Sync”警告消息:

    警告:模块“库”选择了变体“发布”,但模块[“集成测试”]依赖于变体“调试”

  • 这里的问题是,使用“com.android.test”插件的集成测试模块没有“发布”变体

  • 如果我只是尝试将发布构建类型 ( buildTypes { release {} }) 添加到 :integration-test 模块,我会收到:

    错误:VariantInputs 初始化时没有合并清单报告:DEFAULT

项目详情(简体)

该项目包括:

  • a :库模块
  • 一个:app 模块,用于构建应用程序的 apk 并使用 :library 模块
  • 一个:集成测试模块
    • 使用“com.android.test”插件
    • 通过 targetProjectPath ':app' 和 targetVariant 'debug' 依赖于 :app 模块
    • 并包含对 :app 函数的仪器测试
    • 仅包含一个“main”文件夹(测试插件不支持其他)
  • 该项目是在Android 测试蓝图之后构建的,因为这里的目标是:app 模块不知道集成测试模块的存在。

设置.gradle

include :library
include :app
include :integration-test
Run Code Online (Sandbox Code Playgroud)

应用程序/build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

publishNonDefault true

defaultConfig {
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion

    applicationId "xxxxx"

    testInstrumentationRunner rootProject.ext.testInstrumentationRunner

    multiDexEnabled true
    vectorDrawables.useSupportLibrary = true
}

signingConfigs {
    release {
        keyAlias 'xxxx'
    }
}

buildTypes {
    debug {
        testCoverageEnabled = true
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}

// This is needed by the integration-test module (i.e. com.android.test : integration test)
// in order for targetVariant to work without a flavor
publishNonDefault true

testOptions {
    unitTests {
        // Required so that logging methods do not throw not mocked exceptions in junit tests.
        returnDefaultValues = true
    }
}

compileOptions {
    sourceCompatibility rootProject.ext.sourceCompatibility
    targetCompatibility rootProject.ext.targetCompatibility
}
}

dependencies {
// Local dependencies
compile project(':library')
// i cleaned up all the other dependencies as they wouldn't help here
}
Run Code Online (Sandbox Code Playgroud)

问题

有没有人使用 com.android.test 插件获得(集成)测试模块来与Android Gradle Plugin 3.0.1一起运行,而不会出现“无发布变体”错误?如果是这样,我怎样才能避免这个错误,或者我怎样才能将这样的发布变体添加到基于 android 测试插件的模块中(如果这有意义的话)?

coo*_*kie 3

我也得到了

VariantInputs 已初始化,没有合并清单报告:DEFAULT。

然后我完全按照https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint中概述的内容进行操作

当我从测试模块的 Gradle 文件中的“buildTypes”块中删除releasebuildType时,错误消失了。由此:

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
Run Code Online (Sandbox Code Playgroud)

buildTypes {
}
Run Code Online (Sandbox Code Playgroud)