9

I want to customize AndroidManifest in different build types. For example in debug mode I just want an Activity to be exported.

Assume main manifest:

/main/AndroidManifest.xml

<application>
    <activity
        android:name="com.example.MainActivity" />
</application>

Debug manifest:

/debug/AndroidManifest.xml

<application>
    <activity
        android:name="com.example.MainActivity"
        android:exported="true" />
</application>

Example manifest (same as debug):

/example/AndroidManifest.xml

<application>
    <activity
        android:name="com.example.MainActivity"
        android:exported="true" />
</application>

In the debug manifest I get Duplicate registration for activity com.example.MainActivity

That's why I created the example build type.

/build.gradle

android {
    buildTypes {
        example.initWith(buildTypes.debug)
    }
}

But it also doesn't work.

[AndroidManifest.xml:17, AndroidManifest.xml:4] Trying to merge incompatible /manifest/application/activity[@name=com.example.MainActivity] element:
  <activity
--    @android:name="com.example.MainActivity">
--</activity>
--(end reached)
  <activity
++    @android:exported="true"
++    @android:name="com.example.MainActivity">
++</activity>

I'm wondering whether this is a bug, missing feature (will be implemented in the future) or I'm doing something wrong?

I know I can provide different manifest in release and debug (without the one in /main), but I don't think this is a good solution.

EDIT: The solution so far is to define bool in resources and use it inside main manifest. In debug resources the bool will be true while in the release false. This solution seems much better than duplicated manifests, but the question is still actual.

tomrozb
  • 25,773
  • 31
  • 101
  • 122

2 Answers2

4

As of gradle plugin 0.10 it's finally supported. More info about new manifest merger: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger

At the moment (gradle plugin 0.10) it requires this extra configuration in build.gradle

android {
 useOldManifestMerger false
}
tomrozb
  • 25,773
  • 31
  • 101
  • 122
1

I know I can provide different manifest in release and debug (without the one in /main), but I don't think this is a good solution.

Unfortunately, there's a limitation in the merging of manifests where you can't define the same thing (Activity, Service, Receiver, etc.) in the main manifest and the build type manifest. The solution is to define only the non-buildtype specific stuff in the main manifest and everything else in the build type manifests.

Community
  • 1
  • 1
Krylez
  • 17,414
  • 4
  • 32
  • 41
  • The answer to which you're referring to is one year and says, "at this moment". I've seen this topic before I asked this question, anit concerns not arguments of the activity, but it really seems that it's still not implemented rather than a bug. – tomrozb Dec 06 '13 at 09:27
  • The limitation isn't constrained to intent filters. I think this is the [ManifestMerger](https://android.googlesource.com/platform/tools/base/+/master/build-system/manifest-merger/src/main/java/com/android/manifmerger/ManifestMerger.java) class that they currently use and it will only merge similarly named activities if they are identical. – Krylez Dec 06 '13 at 19:32