清单合并对appComponentFactory失败

时间:2018-09-02 08:30:17

标签: android android-studio manifest

使用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.

即使将其添加到清单中,它也会显示 清单合并失败,并出现多个错误

9 个答案:

答案 0 :(得分:11)

我有类似的问题。 gradle.properties文件中的两行:

android.useAndroidX=true
android.enableJetifier=true

要关注的链接:https://developer.android.com/topic/libraries/support-library/androidx-overview#new-project

答案 1 :(得分:7)

此错误在当今很常见:

当我们遇到此类错误时:更新库并提供对AndroidX的使用,但我们正在使用旧的。

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

  • 将您的项目迁移到 AndroidX:
  

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

     

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

此步骤将自动完成所有答案都表示手动执行的所有操作

  • 您可以查看 AndroidX概述 here
  • migration
  • 的更多详细信息

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

  • 使缓存无效并重新启动

OR

  • 清理您的项目

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

答案 2 :(得分:5)

在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'

答案 3 :(得分:4)

  

要解决此问题,您必须添加 tools 名称空间并应用   IDE推荐的application元素的建议属性。

<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

答案 4 :(得分:3)

  

建议:将'tools:replace="android:appComponentFactory"'添加到    AndroidManifest.xml:5:5-19:19中的元素进行覆盖。

如果您添加了tools:replace="android:appComponentFactory",但仍无法解决,请修复它,创建一个新项目,在其中复制粘贴代码和相同的依赖项。在那之后,我希望它应该得到解决。


如果不能解决问题,请尝试添加以下两个:

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

AndroidManifest.xml> <application标签中。

答案 5 :(得分:2)

替换依赖项 来自:

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

收件人:

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

答案 6 :(得分:0)

我也遇到了这个问题,并且按照官方文档迁移到AndroidX。仅通过Refactor->迁移到AndroidX。

Migration to AndroidX Official Docs

希望这会有所帮助。

答案 7 :(得分:-1)

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

答案 8 :(得分:-2)

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