Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a different AndroidManifest.xml only for run tests

Tags:

android

gradle

I have a library with the most simple manifest possible

<manifest package="com.xxx.xxx.android" />

But this library needs to get two metadata values from Android Manifest to work properly, so to run my tests I added to src/test/AndroidManifest.xml the following code:

<manifest package="com.xxx.xxx.android"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <application>
        <meta-data
            android:name="var1"
            android:value="value1"/>
        <meta-data
            android:name="var2"
            android:value="value2"/>
    </application>
</manifest>

As I've read from the documentation I have to set the new AndroidManifest.xml path in gradle. I'm trying to do this way:

android {
    ...
    buildTypes {
        debug {
            testCoverageEnabled true
        }

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

    sourceSets {
        String sharedTestDir = 'src/sharedTest/java'
        String testManifest = 'src/test/AndroidManifest.xml'
        test {
            java.srcDir sharedTestDir
            manifest.srcFile testManifest
        }
        androidTest {
            java.srcDir sharedTestDir
            manifest.srcFile testManifest
        }
    }

    testOptions.unitTests.includeAndroidResources true
}

But it doesn't work and I'm not able to get the metadata in my tests. It only works if I set the manifest.srcFile for main, instead of test and/or androidTest.

like image 426
Victor Laerte Avatar asked Oct 15 '25 18:10

Victor Laerte


1 Answers

Try src/debug/AndroidManifest.xml in combination with testBuildType "debug".

like image 103
Martin Zeitler Avatar answered Oct 17 '25 07:10

Martin Zeitler