0

I have been trying to link my app with Firebase, but after adding json file, and adding some codes in gradle , My android project fails at syncing gradle, this is the error I get when syncing gadle

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:13:5-31:19 to override.

This is my app-level Gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion "29.0.0"
defaultConfig {
    applicationId "app.freeairdrop.io"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 4
    versionName "1.2"
    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.google.firebase:firebase-core:17.0.0'
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'
}
apply plugin: 'com.google.gms.google-services'
Ritesh
  • 67
  • 1
  • 9
  • what are the versions of the Android Support Libraries you are using ? Try to use the same version for all support libraries – Fakher Jul 29 '19 at 15:28
  • Show your app-level `Gradle` file – Taseer Jul 29 '19 at 15:40
  • @TaseerAhmad `dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.google.firebase:firebase-core:17.0.0' 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' } apply plugin: 'com.google.gms.google-services'` – Ritesh Jul 29 '19 at 15:51
  • @Fakher I did not understand about Android Support libraries. What should I do to correct this error? – Ritesh Jul 29 '19 at 15:51
  • Please edit your post and put it there. It's hard to understand here. BTW, you need to migrate to `AndroidX`. Here is one of my [answer](https://stackoverflow.com/a/57189639/9968399) – Taseer Jul 29 '19 at 15:53
  • @TaseerAhmad I have edited the code, please see again !! – Ritesh Jul 29 '19 at 16:03

1 Answers1

1

The reason why it is happening is that Google encourages developers to move to AndroidX flavored dependencies. Old support libraries will be deprecated. So if you still use old support libraries and add a newer updated dependency that makes use of AndroidX, there is a clash between them, hence such error is produced.

enter image description here

Go to Refactor tab and select "Migrate to AndroidX". Follow the instructions. When the conversion is done, clean/rebuild the project. Chances are, after the conversion, your code may contain errors(Unresolved references on imported classes), but that is perfectly fine. All you have to do is to reimport the code you have written but this time with androidx libraries.

Taseer
  • 3,432
  • 3
  • 16
  • 35