Android: Adding Firebase Messaging - Menifest merger failed

I added this to my project:

implementation 'com.google.firebase:firebase-messaging:19.0.0'

and result:

ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:15:5-71:19 to override.

So I go went ahead and added that line to the manifest, and I get this:

 Manifest merger failed with multiple errors, see logs

I went to merging errors, and I see this now:

Error: tools:replace specified at line:15 for attribute android:appComponentFactory, but no new value specified app main manifest (this file), line 14

Here are my current gradle dependencies:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(path: ':bluefire-api-v25.5')
    implementation "com.jakewharton:butterknife:8.5.1"
    annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
    implementation 'com.myhexaville:smart-image-picker:1.0.4'
    implementation 'com.github.gcacace:signature-pad:1.2.1'

    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    implementation 'com.android.support:recyclerview-v7:28.0.0'

    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-messaging:19.0.0'
}

I hit a dead-end. Thoughts?


Solution 1:

To troubleshoot your problem, Follow below steps:

  • Open your AndroidManifest.xml
  • There is a tab on the bottom of the Ide named "Merged Manifest". Open it.
  • This will list out the Merged Manifest at the left and their sources at right.

  • As you are facing Manifest "merger failed" error, you will see Some Merging Errors.

  • This will tell you exactly which part is in conflict. Resolve that and you are done.

In your case, the error is because of the conflict between different support libraries. i.e. between androidx and older support lib. Migrate all your support library to AndroidX. The latest firebase library you are using is already migrated from the Android Support Libraries to the Jetpack (AndroidX) Libraries.

This post will help you to migrate to AndroidX : Migrating to AndroidX

Solution 2:

This Issue occur due to support and andoidx library both present.

Check Firebase Release Note.

This release is a MAJOR version update and includes breaking changes. With this release, libraries are migrated from the Android Support Libraries to the Jetpack (AndroidX) Libraries. The updated libraries will not work unless you make the following changes in your app: Upgrade com.android.tools.build:gradle to v3.2.1 or later. Upgrade compileSdkVersion to 28 or later. Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.

If you have used support version in your gradle, than down firebase version to 18.0.0. Otherwise you need to migrate to androidx.

Solution 3:

I also got the same issue last day. After downgrading 'com.google.firebase:firebase-messaging:19.0.0' to 'com.google.firebase:firebase-messaging:18.0.0', it is fixed