Home » Android » android – androidTest AndroidManifest.xml ignored

android – androidTest AndroidManifest.xml ignored

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have the same issue mentioned in this post AndroidTest Manifest permission not detected

and this post AndroidManifest in androidTest directory being ignored

–> If I put the test manifest in androidTest, debugAndroidTest, androidTestDebug, it never gets picked up and merged.

the answers about putting the AndroidManifest.xml in the debug folder are correct; that does seem to work. (put the test manifest in src/debug

What I want to know is why can’t you put it in the androidTest directory? All the documentation I’ve read while trying to figure this out makes it sound like you should be able to, and that if you can’t then I’m thinking that sounds like some bug in the manifest merger.

For what it’s worth, I’m using Android Studio

How to&Answers:

That is correct and totally agree with you on the confusing documentation. The AndroidManifest.xml under androidTest* source sets would be packaged for the instrumentation APK that does your tests on your actual app APK. If you open the generated APKs for debug and androidTest under build/outputs/apk/ after compiling your app module with the command gradlew assembleDebugAndroidTest (assuming that you haven’t changed the testBuildType in you build.gradle, more info here), you’ll find that any AndroidManifest.xml configuration added under androidTest will be in the androidTest APK and not in your debug app APK.

And also as you said, in case you need test specific configurations like extra permissions, you’ll have to place them in the AndroidManifest.xml under the debug source set instead of main, hence they’ll only be available for testing your app but not in your release build. Of course you can always double check by opening the generated APKs after compiling to make sure that the configuration is right for each build variant.

Answer:

If you need to add extra permissions for tests, you can do it.

You should set the same android:sharedUserId in default AndroidManifest.xml and androidTest/AndroidManifest.xml.

For example:

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:sharedUserId="com.yourpackagename.uid">

    <application
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="android:allowBackup">

    </application>

</manifest>

androidTest/AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:sharedUserId="com.yourpackagename.uid">

    <uses-permission android:name="android.permission.***" />

</manifest>

For details: https://stackoverflow.com/a/14196493/3901000