使用不带发布版本的android测试插件时,避免出现“变量选择冲突"警告 [英] Avoid 'Variant Selection Conflicts' warning when using android test plugin without release variant

本文介绍了使用不带发布版本的android测试插件时,避免出现“变量选择冲突"警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么&问题

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

I updated my Android Studio and Android Gradle Plugin to 3.0.1 and my Gradle Wrapper to 4.1 and can build & deploy my Android Gradle project in release variant on a device via IDE.

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

  • However, the following 'Gradle Sync' warning messages are shown:

警告:模块库"已选择变体发布",但是模块['integration-test']依赖于变体调试"

Warning:Module 'library' has variant 'release' selected, but the modules ['integration-test'] depend on variant 'debug'

  • 这里的问题是,使用'com.android.test'的 integration-test 模块没有'release'变体插件.

  • The problem here is, that there is no 'release' variant for the integration-test module which uses the 'com.android.test' plugin.

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

    If I simply try to add a release build type (buildTypes { release {} }) to the :integration-test module I receive:

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

    Error:VariantInputs initialized with no merged manifest report on: DEFAULT

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

    该项目包括:

    • 一个:图书馆模块
    • 一个:app模块,该模块可构建应用的apk并使用:library模块
    • :集成测试模块,其中:
      • 使用"com.android.test"插件
      • 通过targetProjectPath':app'&依赖于:app模块targetVariant调试"
      • 并包含对:app函数的检测化的测试
      • 仅包含一个主"文件夹(测试插件不支持其他文件夹)
      • a :library module
      • an :app module which builds the app's apk and uses the :library module
      • an :integration-test module which:
        • uses the "com.android.test" plugin
        • dependents on the :app module via targetProjectPath ':app' & targetVariant 'debug'
        • and contains instrumented tests on the :app functions
        • only contains a 'main' folder (the test plugin does not support others)

        settings.gradle

        settings.gradle

        include :library
        include :app
        include :integration-test
        

        app/build.gradle

        app/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 Plugin 3.0.1 一起运行,却没有得到没有发布"的信息变体"错误?如果是这样,该如何避免该错误,或​​者如何在基于android测试插件的模块中添加这样的发行版本(如果完全有道理的话)?

        Did anyone get an (integration-)test module using the com.android.test plugin to run with Android Gradle Plugin 3.0.1 without getting the "no release variant" error? If so, how can I avoid this error or how can I add such a release variant to a android test plugin based module (if this makes sense at all)?

        推荐答案

        我也得到了

        VariantInputs初始化时没有关于DEFAULT的合并清单报告.

        VariantInputs initialized with no merged manifest report on: DEFAULT.

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

        当我从测试模块的Gradle文件中的"buildTypes"块中删除了 release buildType时,错误消失了.从这个:

        The error went away when I removed release buildType from the `buildTypes' block in the test module's Gradle file. From this:

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

        buildTypes {
        }
        

        这篇关于使用不带发布版本的android测试插件时,避免出现“变量选择冲突"警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆