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

问题描述 投票:0回答:4

我正在尝试在我的 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.
android androidx
4个回答
0
投票

转换/升级您的项目以使用 androidX。你有支持和 androidX 的混合体。

我认为Androix Studio中有一个菜单项:Edit -> Convert to AndroidX

要么这样做,要么尝试错误消息中的建议:

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

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.

0
投票

您使用的 Firebase 版本使用

AndroidX
工件。

在此处阅读有关 androidx 的更多信息。

要解决此问题:

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

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

Firebase 发行说明


0
投票
要解决此问题,您必须按以下方式将以下代码添加到清单文件中: 1 - 首先将工具 xmlns 添加到清单标记中:

2-将以下行添加到您的应用程序标记中: 工具:替换=“android:appComponentFactory”

© www.soinside.com 2019 - 2024. All rights reserved.