5

I'm having problem with manifest merger with duplicated receivers but the content is different. I use the following receivers for different API levels, had no issue so far until merger. Build fails due to merger which says

Element receiver#.receivers.UpdateReceiver duplicated with element declared at AndroidManifest.xml:124:9

I don't want to create another receiver and continue with this schema. Is there any way to disable merger for those situations or merge the receivers in one but with the option of enabling action with different intent?

<receiver
    android:name=".receivers.UpdateReceiver"
    android:enabled="@bool/is_api_below_12">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <data android:scheme="package" />
    </intent-filter>
</receiver>

<receiver
    android:name=".receivers.UpdateReceiver"
    android:enabled="@bool/is_api_12_and_above">
    <intent-filter>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
</receiver>
Charles
  • 50,943
  • 13
  • 104
  • 142
Orhan Obut
  • 8,756
  • 5
  • 32
  • 42
  • Never tried it, but it should be legal for 1 receiver tag to have 2 intent filters in it. – Gabe Sechan Jun 27 '14 at 09:07
  • @GabeSechan I need 'enabled' attribute, that would have been great if we had it in intent filter though. – Orhan Obut Jun 27 '14 at 09:12
  • Strictly speaking you don't- you can always have the first line of the receiver be to decide whether to process the intent or not, and to exit if not. Enabled is just a nicer way of doing it. – Gabe Sechan Jun 27 '14 at 09:14
  • Can you give a sample of that? I assume that I can either proceed with intent or completely ignore it? There won't be a selection between intents I guess. I may misunderstood your statement as well. – Orhan Obut Jun 27 '14 at 09:23
  • Yes- you can check which intent you actually got, then check the boolean value you want to base the enable on, and decide whether to process the intent or ignore it. – Gabe Sechan Jun 27 '14 at 09:24
  • But I think If I put both in the same receiver, PACKAGE_REPLACED will be called all the time which is why I wanted to have separate receivers to avoid not getting this intent all the time. – Orhan Obut Jun 27 '14 at 09:30
  • What was your solution finally for Gradle 1.0 or above? Could you perhaps write an answer? – L. G. Apr 28 '15 at 14:18

2 Answers2

1

perhaps you can set

android {
   useOldManifestMerger true
}

in your build.gradle file and this worked fine in my project you can see more details here

Scorpiuszjj
  • 91
  • 1
  • 5
  • unfortunately I need manifest merge since I use placeholders. – Orhan Obut Aug 15 '14 at 13:15
  • 4
    From [the docs](http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger): **In 1.0, we removed the ability to invoke the old manifest merger**. – cprcrack Jan 03 '15 at 22:01
  • How do you use the new merger? I've tried reading this: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger , but it's so complex and confusing... – android developer Jan 05 '15 at 23:49
1

You can find how I fixed your exact same issue in this answer. Basically I created another class, but I made it an static inner class to avoid creating another file to handle a common action.

Community
  • 1
  • 1
cprcrack
  • 17,118
  • 7
  • 88
  • 91