14

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

Community
  • 1
  • 1
joshkendrick
  • 3,497
  • 8
  • 38
  • 52
  • Saying "I have the same issue" makes this NOT any less of a duplicate, **see:** [AndroidManifest in androidTest directory being ignored](https://stackoverflow.com/questions/26244998/androidmanifest-in-androidtest-directory-being-ignored) – Top-Master Apr 06 '23 at 17:48

2 Answers2

5

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.

PLNech
  • 3,087
  • 1
  • 23
  • 52
ahasbini
  • 6,761
  • 2
  • 29
  • 45
-2

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

m.myalkin
  • 1,128
  • 1
  • 10
  • 18
  • This is not the way to go because of security reasons. You will end up with the sharedUserId flag set in your release product. – Juke Jan 25 '19 at 16:11
  • @Juke sharedUserId can be set only for debug build in debug/AndroidManifest.xml – m.myalkin Jan 26 '19 at 17:19
  • Where did you get this information? The documentation mentions nothing about the flag being limited to debug builds. In fact it explicitly mentions that the certificate of the apps has to be identical. This mechanism should protect from access by e.g. an hijacked app. Though i would recommend using sharedUserId only if really needed. – Juke Jan 28 '19 at 12:08
  • @Juke to set this flag only for debug builds you should put it in debug/AndroidManifest.xml as I mentioned earlier. Then it will not be shipped to production. This flag can be useful for example for ui tests permissions, if you want to add permissions only when instrumentation apk is installed. – m.myalkin Jan 31 '19 at 00:22