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.