这是什么意思?将<tools:replace =“ android:appComponentFactory”添加到<application>元素

时间:2019-12-04 12:57:51

标签: android androidx

我正在尝试在Android应用程序中使用Firebase。

这是我的Build.gradle文件

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'

当我删除以下代码行并运行该应用程序时,该应用程序运行正常。

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

但是当我添加以上行并运行代码时,应用程序显示以下错误:

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.

这是什么意思?

Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-24:19 to override.

3 个答案:

答案 0 :(得分:0)

转换/升级您的项目以使用androidX。您周围有多种支持和androidX。

我认为Androix Studio中有一个菜单项:编辑->转换为AndroidX

这或者您尝试从错误消息中尝试建议:

 Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.

答案 1 :(得分:0)

错误消息为您的问题提供了解决方案

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.

您需要在清单中添加一个替换标签:

Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.

答案 2 :(得分:0)

您使用的Firebase版本使用了AndroidX工件。

详细了解androidx here

要解决此问题:

  • 将项目迁移到AndroidX 和Target API 29

  • 在项目中使用较低版本的Firebase 来避免它。

Firebase release note

相关问题