26

Is it possible to have different manifest files for the debug and release versions of my APK in Android Studio?

Normally I don't have need for such a such a thing but in debug mode, my applications run in a different user id and process and this is defined in the manifest. I've attached a diff of what my debug manifest has:

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,5 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.mridang.address"
+    android:sharedUserId="com.mridang.dashclock"
     android:versionCode="10"
     android:versionName="1.0" >

@@ -14,6 +15,7 @@
     <application
         android:allowBackup="true"
         android:icon="@drawable/ic_launcher"
+        android:process="com.mridang.dashclock"
         android:label="@string/application_name"
         android:theme="@android:style/Theme.Holo.Light.DarkActionBar" >

I'm losing my mind with stashing the debug manifest file and popping it before building and if two separate manifests were possible, that would be great.

Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382

3 Answers3

42

Create a "debug" folder under src/ and put it in there: https://github.com/androidfu/Now-Playing/tree/master/app/src

My "release" manifest is in src/main/, but I'm pretty sure if you needed two wholly separate manifest files you could use src/release/ and src/debug/.

Bill Mote
  • 12,644
  • 7
  • 58
  • 82
  • That example looked really helpful. Will Android automatically merge both of the manifests or do I need to modify something in my Gradle config? That example was exactly what I needed, as it looks like I don't need to have two separate manifests but only the diff parts. – Mridang Agarwalla Mar 28 '15 at 13:30
  • 2
    @MridangAgarwalla: "Will Android automatically merge both of the manifests" -- yes. "it looks like I don't need to have two separate manifests but only the diff parts" -- probably. Manifest merging is complicated, and so depending on what you're trying to do, you may need to provide Gradle for Android a bit more help: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger – CommonsWare Mar 28 '15 at 13:36
  • I've done nothing other than define debug {} and release {} buildTypes in my app/build.gradle file. – Bill Mote Mar 28 '15 at 13:38
  • 1
    @CommonsWare: I just tried it and looks like the manifests are merged automatically. I did not get the `INSTALL_FAILED_UID_CHANGED` error and the APK worked. – Mridang Agarwalla Mar 28 '15 at 13:42
  • 5
    Android Studio 1.4 shows only `debug` Manifest, but `release` doesn't – Konstantin Konopko Nov 17 '15 at 16:47
7

For those of us who have variants in their app and still need to customize the debug manifest for usage in their variants, these following bits of information might help:

  1. The order in which we override with the source sets is probably the most important thing because the merge cascades down the priority chain. If we want all debug builds to have the manifest, then we should put it in the src/debug folder - then all variant's manifests will override this one. If you want to have the debug manifest to apply to only a particular variant then you should put it at src/variantnameDebug/AndroidManifest.xml
  2. The name of the variant must absolutely match the folder's name. The Build Variants sidebar shows the list of the variant names, as well as the selected full name's variant. Another way to get a comprehensive report of the possible folder locations for the source sets is to run the gradle task at /Tasks/android/sourceSets from the Gradle sidebar on the right.
  3. The Merged Manifest view is essential and probably the most helpful tool to debug what's happening. Look to the bottom of the editor's tab bar when you have any Manifest file open. Switching to this view gives a compiled, colorized report of all manifests merged together along with any errors and suggestions.

Detailed documentation on this merging is here: https://developer.android.com/studio/build/manifest-merge

Dhiraj Gupta
  • 9,704
  • 8
  • 49
  • 54
4

Yes, it is possible. Use this paths:

Debug Manifest: ../src/debug/AndroidManifest.xml

Release Manifest: ../src/release/AndroidManifest.xml


Show Release Manifest on Android Studio:

  1. Open Build Variants Window
  2. Change from debug to release
  3. Will be visible on Project -> Android -> manifests
Paulo Pereira
  • 1,750
  • 1
  • 12
  • 23