1

I am trying to use firebase in my Android Application.

This is my Build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.ecommerce5"
        minSdkVersion 27
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    implementation 'com.google.firebase:firebase-analytics:17.2.0'

    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'
}

apply plugin: 'com.google.gms.google-services'

When I remove the following line of code and run the application, the application runs fine.

implementation 'com.google.firebase:firebase-analytics:17.2.0'

But when I add the above line,and run the code, the application shows the following error:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-rc02] 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:5:5-19:19 to override.

What does this mean?

Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-24:19 to override.
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Anwesa Roy
  • 67
  • 1
  • 10
  • You have to migrate your project to `AndroidX` to use latest version of `Firebase` components – Md. Asaduzzaman Dec 04 '19 at 13:02
  • Check steps here for Migration: https://stackoverflow.com/a/59171476/2637449 – Md. Asaduzzaman Dec 04 '19 at 13:03
  • `firebase-analytics:17.2.0` is latest version which requires androidx. Migrate to androidx or degrade the version – Vir Rajpurohit Dec 04 '19 at 13:04
  • Does this answer your question? [Android Material and appcompat Manifest merger failed](https://stackoverflow.com/questions/51793345/android-material-and-appcompat-manifest-merger-failed) – Md. Asaduzzaman Dec 04 '19 at 13:07
  • @Md.Asaduzzaman Hi, I tried migrating to androidX. It shows the following message: "Cannot perform refactoring operation. There were changes in code after usages have been found.". – Anwesa Roy Dec 04 '19 at 13:08
  • @VirRajpurohit Hi, I tried migrating to androidX. It shows the following message: "Cannot perform refactoring operation. There were changes in code after usages have been found.". – Anwesa Roy Dec 04 '19 at 13:08

3 Answers3

0

Convert/upgrade your project to use androidX. You have a mixture of support and androidX around.

I think there is a menu item in Androix Studio: Edit -> Convert to AndroidX

Either this or you try the suggestion from the error message:

 Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
Grisgram
  • 3,105
  • 3
  • 25
  • 42
  • Hi, I tried migrating to androidX. It shows the following message: "Cannot perform refactoring operation. There were changes in code after usages have been found.". How can I do the latter? – Anwesa Roy Dec 04 '19 at 13:07
0

The error message provides the solution to your problem

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-rc02] 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:5:5-19:19 to override.

You need to add a replace tag to your manifest:

Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
MichaelStoddart
  • 5,571
  • 4
  • 27
  • 49
  • Hi, I tried doing this. Still the problem persists. It shows the following error: Manifest merger failed with multiple errors, see logs – Anwesa Roy Dec 04 '19 at 14:41
0

You have used a version of firebase that uses AndroidX artifacts.

Read more about androidx here.

To resolve this:

  • Migrate project to AndroidX and Target API 29

  • Use a lower version of firebase in your project to avoid it.

Firebase release note

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117