I try (in a sample app), to have one single ":test" module testing the main module ":app" and ":dynamicfeature" module. For that, I use the "com.android.test" gradle plugin.

My ":app" module runs just fine. It instanciates a basic view from my ":dynamicmodule".

Unfortunately, my ":test" module fails during "processDebugManifest".

Error is :

Failed to calculate the value of task ':test:processDebugManifest' property 'testedApplicationId'.

Collection has more than one element.

In fact it seems the test module does not accept to implement a "com.android.application" module AND "com.android.dynamic-feature" module

Any idea? Thanks

Here is my build.gradle (:test)

plugins {
   id 'com.android.test'
   id 'kotlin-android'
}
android {
   compileSdkVersion 30
   buildToolsVersion "30.0.2"
   publishNonDefault true

   defaultConfig {
       minSdkVersion 21
       targetSdkVersion 30
       testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   }

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

       }
   }
   compileOptions {
       sourceCompatibility JavaVersion.VERSION_1_8
       targetCompatibility JavaVersion.VERSION_1_8
   }
   kotlinOptions {
       jvmTarget = '1.8'
   }
   targetProjectPath ':app'
   targetVariant 'debug'
}
dependencies {
   implementation project(":app")
   implementation project(":dynamicfeature")
   implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
   implementation 'androidx.core:core-ktx:1.3.2'
   implementation 'androidx.appcompat:appcompat:1.2.0'
   implementation 'com.google.android.material:material:1.2.1'

   implementation 'androidx.test.ext:junit:1.1.2'
   implementation 'androidx.test.espresso:espresso-core:3.3.0'
   implementation 'androidx.test:core:1.0.0'}

Here is my build.gradle (:app)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"


    defaultConfig {
        applicationId "com.sample.app"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    dynamicFeatures = [':dynamicfeature']
}

dependencies {

    implementation "com.google.android.play:core:1.8.3"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Here is my build.gradle (:dynamicfeature)

plugins {
    id 'com.android.dynamic-feature'
    id 'kotlin-android'
}
android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        publishNonDefault true
        applicationId "com.sample.module"
        minSdkVersion 21
        targetSdkVersion 30
    }

    buildTypes {
        release {
            minifyEnabled false
        }
        debug{

        }
    }
}

dependencies {
    implementation project(":app")
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    testImplementation 'junit:junit:4.+'
}
2

There are 2 answers

0
Bilgehan KALKAN On

Unfortunately I couldn't find any solution for this bug/behavior. I'll continue with androidTest sourceSet.

When I tried to remove :app dependency from :test module, TestVariantImpl#calculateTestedApplicationId still gets 2 manifest paths on elements.

Error happens from these file references, this should be single sized Set.

["/{project-path}/{app-module}/build/intermediates/packaged_manifests/debug",
"/{project-path}/{dynamic-feature-module}/build/intermediates/packaged_manifests/debug"]

Exception call side: TestVariantImpl#198

0
Thu Vu On

The error caused by your test gradle.build having 2 dependencies:

implementation project(":app") implementation project(":dynamicfeature")

It has app dependency by default so the collection would be: "app, app, dynamicfeature". That's why your error message you got is "Collection has more than one element."

If you remove these 2 dependencies, the error would be disappeared, although I know you would get other errors from your code.

This is an issue from Android/Gradle as this advance test setup https://developer.android.com/studio/test/advanced-test-setup#use-separate-test-modules-for-instrumented-tests does not work for multi modules project