Navid Eivazzadeh Navid Eivazzadeh - 1 month ago 20
Android Question

Manifest merger failed with multiple errors when adding firebase messaging service to my AndroidManifest.xml file

I was hoping to add Firebase cloud messaging to my app. I followed codelab tutorial for this and it was working correctly for the sample app, but when I try to add

<service>
tags to my application Manifest merger errors occurs.

The strange part is that it is working without adding those services to my Manifest file!

Here it is the error:


Error:packageName/app/src/main/AndroidManifest.xml:52:9-58:19 Error:
Element service#packageName.firebase.MyFirebaseInstanceIdService at AndroidManifest.xml:52:9-58:19 duplicated with element declared at AndroidManifest.xml:44:9-50:19
packageName/app/src/main/AndroidManifest.xml Error:
Validation failed, exiting
FAILURE: Build failed with an exception.


  • What went wrong:
    Execution failed for task ':app:processDebugManifest'.
    Manifest merger failed with multiple errors, see logs

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.




And this is part of my AndroidManifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.violete.selfienight">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name="net.violete.selfienight.leafpic.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.FullScreen">
<activity
android:name=".CameraActivity"
android:icon="@mipmap/ic_launcher"
android:label="@string/title_camera_activity"
android:screenOrientation="landscape"
android:taskAffinity=".CameraActivity"
android:theme="@style/AppTheme.FullScreen">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<service
android:name=".firebase.MyFirebaseInstanceIdService"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<service
android:name=".firebase.MyFirebaseInstanceIdService"
>
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
...
</application>
</manifest>


My question is that whether Firebase library adds these tags to my Manifest during building or something is wrong here?

Answer

You have the same service (.firebase.MyFirebaseInstanceIdService) listed twice. This will not work. Either have one <service> element containing two <intent-filter> elements, or have two separate services with separate classes.

Comments