Gradle 由于清单合并导致同步失败
Gradle sync fails due to Manifest Merger
我一直在尝试使用 Firebase link 我的应用程序,但是在添加 json 文件并在 gradle 中添加一些代码后,我的 android 项目失败了正在同步 gradle,这是我在同步 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 文件:
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
的较新的更新依赖项,则它们之间存在冲突,因此会产生此类错误。
转到“重构”选项卡并select "Migrate to AndroidX"。按照说明进行操作。转换完成后,clean/rebuild 项目。很有可能,在转换之后,您的代码可能包含错误(导入时未解析的引用 类),但这完全没问题。您所要做的就是重新导入您编写的代码,但这次使用 androidx
个库。
我一直在尝试使用 Firebase link 我的应用程序,但是在添加 json 文件并在 gradle 中添加一些代码后,我的 android 项目失败了正在同步 gradle,这是我在同步 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 文件:
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
的较新的更新依赖项,则它们之间存在冲突,因此会产生此类错误。
转到“重构”选项卡并select "Migrate to AndroidX"。按照说明进行操作。转换完成后,clean/rebuild 项目。很有可能,在转换之后,您的代码可能包含错误(导入时未解析的引用 类),但这完全没问题。您所要做的就是重新导入您编写的代码,但这次使用 androidx
个库。