4

我想做什么&问题

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

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

    警告:模块 'library' 选择了变体 'release',但模块 ['integration-test'] 依赖于变体 'debug'

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

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

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

有关项目的详细信息(简化)

该项目包括:

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

设置.gradle

include :library
include :app
include :integration-test

应用程序/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
}

问题

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

4

1 回答 1

3

我也越来越

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

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

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

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

buildTypes {
}
于 2018-08-24T21:10:32.213 回答