Android manifest merger fails for receivers with s

2020-04-06 13:18发布

问题:

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>

回答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



回答2:

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.