由于清单合并,Gradle同步失败 [英] Gradle sync fails due to Manifest Merger

查看:87
本文介绍了由于清单合并,Gradle同步失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图将我的应用程序与Firebase链接,但是在添加json文件并在gradle中添加一些代码之后,我的android项目无法同步gradle,这是我在同步gadle时遇到的错误

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.

这是我的应用程序级别的Gradle文件:

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'

推荐答案

之所以如此,是因为Google鼓励开发人员转而使用AndroidX风味的依赖项.旧的支持库将被弃用.因此,如果您仍然使用旧的支持库并添加使用AndroidX的更新的依赖项,则它们之间会发生冲突,因此会产生此类错误.

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.

转到重构"选项卡,然后选择迁移到AndroidX".请按照说明进行操作.转换完成后,清理/重建项目.转换后,您的代码可能会包含错误(在导入的类上有未解决的引用),但这完全可以.您要做的就是重新导入您编写的代码,但这一次是使用androidx库.

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.

这篇关于由于清单合并,Gradle同步失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆