Avoid 'Variant Selection Conflicts' warning when using android test plugin without release variant

10k views Asked by At

What I want to do & the problem

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.

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

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

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

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

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

Details about the project (simplified)

The project consists of:

  • 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)
  • This project is build after the Android Test Blueprint as the goal is here that the :app module does not know anything about the integration-test module's existence.

settings.gradle

include :library
include :app
include :integration-test

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
}

Question

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)?

1

There are 1 answers

2
cookie On

I was also getting

VariantInputs initialized with no merged manifest report on: DEFAULT.

Then I followed exactly what is outlined in the https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint

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'
    }
}

to

buildTypes {
}