简体   繁体   中英

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

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 .

尝试将src/debug/AndroidManifest.xmltestBuildType "debug"结合使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM