0

I have the following modules inside my project for which I cannot get Gradle to merge the Android manifests properly:

myproject_alpha
myproject_beta
myproject_lib
myproject_release

The *_lib module is the main module for the project that contains all source code. The other 3 modules are "wrapper modules" that make slight modifications to the content providers' "authorities" parameter, change the "data" field inside an activity's intent filter specified in the *_lib module's manifest, plus enable some other activities not present in myproject_release module.

Currently, I have gradle Android manifest merging errors between alpha (or beta or release) vs lib. For example, between lib and alpha I see the following 2 gradle errors:

Trying to merge incompatible /manifest/application/provider[@name=com.myproject.contentprovider.MyProvider] element:
  <provider
--    @android:authorities="com.myproject.alpha.provider"
  <provider
++    @android:authorities="com.myproject.lib.provider"

:myproject_alpha:processDebugManifest FAILED

Trying to merge incompatible /manifest/application/activity[@name=com.myproject.activity.LoginActivity] element:
  <activity
  @android:name="com.myproject.activity.LoginActivity"
          @android:name="android.intent.action.MAIN">
          @android:name="android.intent.category.LAUNCHER">
  <intent-filter>
          @android:name="android.intent.action.VIEW">
          @android:name="android.intent.category.BROWSABLE">
          @android:name="android.intent.category.DEFAULT">
      <data
--            @android:host="myhost.test.com"
  <activity
  @android:name="com.myproject.LoginActivity"
          @android:name="android.intent.action.MAIN">
          @android:name="android.intent.category.LAUNCHER">
  <intent-filter>
          @android:name="android.intent.action.VIEW">
          @android:name="android.intent.category.BROWSABLE">
          @android:name="android.intent.category.DEFAULT">
      <data
++            @android:host="myhost.com"

:myproject_alpha:processDebugManifest FAILED

The only similar question I found was
Gradle: How to merge Android manifest files for different buildTypes which need the same Activity, but with different intent-filters. However, it doesn't really match my issue because in my case "lib" and "alpha" are interdependent modules not different builds. I'll appreciate some feedback.

Community
  • 1
  • 1
cavega
  • 485
  • 3
  • 11
  • 23

3 Answers3

1

I have issues with the answer above in that when I compile, I always get the message

Invalid instruction 'merge', valid instructions are : REMOVE,REPLACE,STRICT

I found success in importing the tools as in @swooby answer and then adding tools:node="merge" in the <activity> tag for the Activity being launched I want to replace and then adding

<intent-filter tools:node="remove">
                <action android:name="android.intent.action.MAIN"/>

to the Activity's launcher that I do not want to have a launcher icon

Hope this helps.

AllDayAmazing
  • 2,383
  • 1
  • 24
  • 25
  • Thank you for the update. The previous solution must have bit rotted. I verified that this works as I expect in both product flavors that I'm using it for, by inspecting the generated intermediate manifest. – Oded Sep 16 '16 at 05:48
0

If you examine the class that merges the manifests, you'll see that the mergeNewOrEqual() method is not smart enough to merge elements that are not identical. Unfortunately, this is the method that is used to merge providers and activities.

So the only "solution" would be to either to only define the elements in one place, or to give them identical signatures in both definitions.

Krylez
  • 17,414
  • 4
  • 32
  • 41
  • Thanks for the link, it was useful. We inherited the code from an outside team, so not sure if they ever got the code to build as it is. For now I edited all manifests to use the same signatures and on a future release I'll restructure the codebase to make better use of gradle. – cavega Jan 22 '14 at 22:54
0

Declare the header of your manifest as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

Then, use one of the following appropriate attributes on any activity, activity-alias, service, receiver, or provider element that you want to merge:

tools:merge="override"
tools:merge="remove"

This info was gleaned from:
https://android.googlesource.com/platform/tools/base/+/idea133/build-system/manifest-merger/src/main/java/com/android/manifmerger/ManifestMerger.java

swooby
  • 3,005
  • 2
  • 36
  • 43
  • Please explain "doesn't work". What does the merged manifest look like? Please provide a copy of the sub-manifest and the super-manifest. – swooby Mar 07 '14 at 20:13
  • It will say: Trying to merge incompatible /manifest/application/activity[@name=#provider#] element: – Alvaro Ardila Mar 07 '14 at 20:14
  • What type of element are you trying to merge? Please provide a snippet of your manifests. – swooby Mar 15 '14 at 07:50
  • Your solution doesn't work: I want to merge android:uiOptions ,bug failed – muyiou May 20 '14 at 09:00