appComponentFactory [duplicate]的清单合并失败

问题描述 投票:18回答:9

这个问题在这里已有答案:

使用Google所谓的Material Design 2.0需要您添加

implementation 'com.google.android.material:material:1.0.0-rc01'

在应用程序Gradle中也包括

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

这显示了冲突

这是日志所说的内容

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-rc01] 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.

即使在将其添加到Manifest之后,它也显示Manifest Merger因多次错误而失败

android android-studio manifest
9个回答
19
投票

现在这个错误很常见:

当我们得到这种类型的错误时:更新库并提供AndroidX的使用,但我们使用旧的。

您可以按照以下步骤解决此问题:

  • 将项目迁移到AndroidX:

使用Android Studio 3.2及更高版本,您可以通过从菜单栏中选择Refactor> Migrate to AndroidX,快速迁移现有项目以使用AndroidX。

注意:要迁移不使用任何需要转换的依赖项的第三方库的现有项目,可以将android.useAndroidX标志设置为true,将android.enableJetifier标志设置为false。

这一步将自动完成一切所有答案都应该手动完成

即使您遇到任何其他错误,如运行时构建失败,那么:

  • 使缓存无效并重新启动

要么

  • 清理您的项目

希望它对所有人都有帮助。谢谢。


7
投票

要解决此问题,您必须添加工具命名空间并将建议的属性应用于IDE建议的应用程序元素。

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
    package="your.package.uri">

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="android:appComponentFactory"
        android:appComponentFactory="androidx">

Source


6
投票

在build.gradle文件中用androidx替换所有android依赖项。

例如:

implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'androidx.annotation:annotation:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

5
投票

建议:在tools:replace="android:appComponentFactory":5:5-19:19中添加'AndroidManifest.xml'元素以覆盖。

如果您添加了tools:replace="android:appComponentFactory"并且仍然通过修复它而遇到麻烦,请创建一个新项目,将代码和相同的依赖项复制粘贴到那里。在那之后,我希望它应该是固定的。


如果它没有解决问题,请尝试添加以下两个:

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"

AndroidManifest.xml> <application标签当然。


2
投票

替换依赖项:

implementation 'com.google.android.material:material:1.0.0-rc01'

至:

implementation 'com.android.support:design:28.0.0'

0
投票

我也有这个问题,我按照官方文档迁移到AndroidX。只能通过Refactor - >迁移到AndroidX。

Migration to AndroidX Official Docs

希望这可以帮助。


-1
投票

尝试:替换rc01 >> alpha1。它对我有用!


-2
投票

取消选择即时运行对我有用。不确定它是否对每个人都有帮助。

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