6

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

hb0
  • 3,350
  • 3
  • 30
  • 48
  • Your library contain flavors and your *app* cannot choose between these flavor, try update Gradle Wrapper to 4.3, if doesn't work provide your build.gradle for app. –  Nov 28 '17 at 10:57
  • Updating gradlew to 4.3 did not change anything. I added the requested app/build.gradle file. To clearify: The app has the build types "release" and "debug", the library does not define anything like that by itself, but all "Build Variants" in Android Studio shows both (release/debug) for all modules but integration-test module, which only has "debug" and which is why I see the error when all others are set to "release". – hb0 Nov 28 '17 at 11:17
  • I see, I suggest this [answer](https://stackoverflow.com/questions/45679847/android-studio-3-0-compile-issue-cannot-choose-between-configurations/45685318#45685318) for you which have similar issue to your. Notice other answers in the same question they maybe useful for you. –  Nov 28 '17 at 11:21
  • Looks interesting, but I don't fully get it: In which build.gradle do I need to define the `configurations`? **1)** The integration-test's does not have the dependency :app/:library, it uses `targetProjectPath ':app'` and `targetVariant 'debug'` to set the dependency as this uses com.android.test plugin. The :app module depends on the :library modul. **2)** The :app's build file does not dependent on :integration-test module (ofc). – hb0 Nov 28 '17 at 11:34
  • You don't need to define configurations until you need it. 1- *integration=test's* shouldn't have the dependency *app*. 2-Once you added *integration=test's* to your *app* dependency that's make app dependent on it. finally did you tried the solution suggested there in your case it will be `implementation project(path path: ':library', configuration: 'default')` instead of `compile project(':library')` –  Nov 28 '17 at 11:41
  • **1)** The :integration-test module tests the :app, so I need to define :app as targetProject, else I can't execute tests on it. **2)** I don't want the :app to know about the :integration-test module's existence. We might want to deliver the app without the integration test module code one day soon **3)** With `implementation project` in :app to define the :library dependency the :app does not build anymore: *./app/build/intermediates/manifests/full/debug/AndroidManifest.xml* processing fails (e.g. it can't find :library resources etc) **4)** I need to create a sample project when I find time – hb0 Nov 28 '17 at 11:56
  • 1
    It was very hard work to get this "clean" setup running (integration tests use the app's apk and the app does not depend on the integration test module) as Android Build Tools 3.0.0 wasn't able to merge the Manifests. Now I can build, run all tests, and deploy it - so the warning is something I can live with for some time. Thank you for all your suggestions and explanations. I'll try to create a sample project for this issue but it might take a little time. This setup is build after the Blueprint: https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint – hb0 Nov 28 '17 at 12:01
  • @hb0 Any chance you can show us how you solved this problem? I am facing a similar issue with the `com.android.test` plugin at the moment. – jenzz Mar 19 '18 at 21:14
  • @jenzz: I'm ill right now for a couple of weeks. When I remember correctly the last state was just the warnings which weren't a big problem for me at that time - right now my colleagues are refactoring the project so we won't use com.android.test anymore afaik... Sorry. – hb0 Mar 21 '18 at 08:15

1 Answers1

3

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 {
}
cookie
  • 81
  • 9
  • Sounds promising. Unfortunately, I cannot test this right now as I don't have an ongoing project with the error. Can others replicte the fix? If so, I'll mark this as the correct answer. – hb0 Aug 29 '18 at 09:06
  • This worked for me. I created the test module with Android Studio using "File->New->Library Project" as a standard android library module. This created a default library-module style build.gradle file. Removing the buildTypes fixed the gradle error. – dell116 Jan 15 '19 at 19:03