【问题标题】:Manifest Merger fails for appComponentFactory [duplicate]appComponentFactory 的清单合并失败 [重复]
【发布时间】:2018-09-02 08:30:16
【问题描述】:

使用谷歌所谓的 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.

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

【问题讨论】:

    标签: android android-studio manifest


    【解决方案1】:

    这个错误现在很常见:

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

    您可以按照以下步骤解决:

    • 将您的项目迁移到 AndroidX:

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

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

    此步骤将自动完成所有答案所说的手动操作

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

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

    • 使缓存失效并重新启动

    • 清理您的项目

    希望对大家有所帮助。 谢谢。

    【讨论】:

    • 我更喜欢这个,因为它会自动备份我们的旧项目。
    • 请记得点击“迁移到AndroidX”后点击左下角的“Do refactor”
    • 这个解决方案就像一个魅力
    • 只是为了进一步提供帮助:在 gradle.properties 中设置 android.useAndroidX=true,对于 enableJetifier 也是如此
    【解决方案2】:

    要解决此问题,您必须添加 tools 命名空间并应用 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

    【讨论】:

    • 这给出了问题:工具:在第 23 行为属性 android:appComponentFactory 指定了替换,但没有指定新值
    【解决方案3】:

    建议:添加“tools:replace="android:appComponentFactory"”到 AndroidManifest.xml:5:5-19:19 的元素要覆盖。

    如果您添加了tools:replace="android:appComponentFactory",但修复它仍然有问题,请创建一个新项目,将代码和相同的依赖项复制粘贴到那里。在那之后,我希望它应该被修复。


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

    tools:replace="android:appComponentFactory"
    android:appComponentFactory="androidx"
    

    当然是在AndroidManifest.xml > &lt;application 标签中。

    【讨论】:

    • java.lang.ClassNotFoundException:找不到类“site.foxtransport.foxtaxi.whateverString”
    • 你可以试试android:appComponentFactory="androidx"吗?
    • 是的,我试过了,谢谢。在这种情况下,低于 API 28 的任何东西看起来都是不兼容的
    【解决方案4】:

    将 build.gradle 文件中的所有 android 依赖项替换为 androidx 的依赖项。

    例如:

    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】:

    替换依赖 来自:

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

    到:

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

    【讨论】:

      【解决方案6】:

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

      【讨论】:

      • 我认为这可以是评论而不是答案
      【解决方案7】:

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

      Migration to AndroidX Official Docs

      希望这会有所帮助。

      【讨论】:

        【解决方案8】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-08
          • 1970-01-01
          • 1970-01-01
          • 2019-11-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多