Manifest merger failed : Attribute application@app

2020-01-27 07:20发布

问题:

I am trying to add firebase in my project but when I implement 'com.google.firebase:firebase-messaging:19.0.0' and 'com.google.firebase:firebase-core:17.0.0'.

build.gradle(here is the error)

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

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

 dexOptions {
    javaMaxHeapSize "2g"
 }
}

dependencies {
 implementation 'com.roughike:bottom-bar:2.0'
 implementation 'com.android.support:support-v4:28.0.0'
 implementation 'com.android.support:exifinterface:28.0.0'
 implementation 'com.android.support:animated-vector-drawable:28.0.0'
 implementation 'com.flaviofaria:kenburnsview:1.0.7'
 implementation fileTree(include: ['*.jar'], dir: 'libs')
 implementation 'com.android.support:appcompat-v7:28.0.0'
 implementation 'com.android.support.constraint:constraint-layout:1.1.3'
 implementation 'com.android.support:design:28.0.0'
 implementation 'com.github.chrisbanes:PhotoView:2.1.4'
 implementation 'com.google.firebase:firebase-messaging:19.0.0'
 implementation 'com.google.firebase:firebase-core:17.0.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'
 implementation 'com.android.support:recyclerview-v7:28.0.0'
 implementation 'com.android.support:cardview-v7:28.0.0'
 implementation "com.google.android.gms:play-services-location:17.0.0"
 implementation 'com.google.android.gms:play-services-maps:17.0.0'
 implementation 'com.google.android.gms:play-services-base:17.0.0'
 implementation 'com.github.ahmedshaban1:EasySlider:1.0.0'
 implementation 'com.liangfeizc:SlidePageIndicator:1.1.0@aar'
 implementation 'me.relex:circleindicator:1.2.2@aar'
 implementation 'com.github.bumptech.glide:glide:4.8.0'
 annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

}

the other gradle file:

buildscript {

 repositories {
    google()
    jcenter()
 }
 dependencies {
    classpath 'com.android.tools.build:gradle:3.4.1'
    classpath 'com.google.gms:google-services:4.2.0'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
 }

  allprojects {
    repositories {
     google()
     mavenCentral()
     jcenter()
     maven {
        url "https://maven.google.com"
        }
     maven { url "https://jitpack.io" }
   }
  }

  task clean(type: Delete) {
   delete rootProject.buildDir
  }

The error that show about com.android.support:support-v4:28.0.0:

Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='cardview-v7', myVersion='28.0.0', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.coordinatorlayout', myArtifactId='coordinatorlayout', myVersion='1.0.0', myPacking='aar', myClassifier='null'} incompatible dependencies

Inspection info:There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).

Also when I build the apk it shows this 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 element at AndroidManifest.xml:13:5-354:19 to override.

adding tools:replace="android:appComponentFactory" doesn't work though

回答1:

With new 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.

Method-1 :

add this two in your gradle.properties File, without updating anything

android.useAndroidX=true
android.enableJetifier=true

Method-2

if Method-1 doesn't solve your problem do one thing if you are using android studio version 3.2 or higher go to Refactor>Migrate to AndroidX...



回答2:

Either downgrade those Firebase dependencies - or migrate to androidx.

The Jetifier is rather useless, because having control over the own dependencies.



回答3:

According to the firebase site to solve this issue:

  • Update your app to use Jetpack (AndroidX), you can do this by adding these two lines: android.useAndroidX=true and android.enableJetifier=true into file gradle.properties in the project root directory. Or you can do another method
  • Upgrade com.android.tools.build:gradle to v3.2.1 or later (in project build.gradle file)
  • Upgrade compileSdkVersion to 28 or later (in project build.gradle file)


回答4:

You are using both support libraries and androidx libraries and you can't do it.

Cloud Messaging version 19.0.0 is in the June release. Check the official release notes of Firebase Libraries:

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.


回答5:

Try this and sync your project, if this can help you

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'