【问题标题】:How can i remove manifest merge errors如何删除清单合并错误
【发布时间】:2019-10-01 11:37:44
【问题描述】:

我在没有使用 androidx 的项目中添加了 MaterialAlertDialog。这会在下一次构建期间导致错误。所以我从应用程序级别的构建 gradle 中删除了“实现”语句。但是当我尝试构建我的项目时,我仍然遇到明显的合并错误。

这是我在构建时遇到的错误

清单合并失败:属性 application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 也存在于 [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory)。 建议:将 'tools:replace="android:appComponentFactory"' 添加到 AndroidManifest.xml:19:5-152:19 的元素以覆盖。

到目前为止,我已经尝试了以下解决方案,关闭并重新加载我的项目。清理并重建。删除我项目中的 .gradle 和 .idea 文件夹并重新构建它

这些是我项目中的依赖项

    dependencies 
    {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
            })
        implementation "com.android.support:appcompat-v7:${android_support_version}"
        implementation "com.android.support:design:${android_support_version}"
        implementation 'com.github.lzyzsd:circleprogress:1.1.0@aar'
        implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1@aar'
        implementation 'commons-net:commons-net:3.3'
        implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
            transitive = true
        }

        implementation "de.hdodenhof:circleimageview:${circle_imageview}"
        implementation "com.github.bumptech.glide:glide:${glide_version}"
        implementation "com.android.support:recyclerview-v7:${android_support_version}"
        implementation "com.android.support:cardview-v7:${android_support_version}"
        implementation "com.squareup.retrofit2:retrofit:${retrofit_service_version}"
        implementation "com.squareup.retrofit2:converter-gson:${retrofit_gson_convertor}"
        implementation "com.clough.android.androiddbviewer:androiddbviewer:${dbviewer_version}"
        implementation "com.android.support:multidex:${multidex_version}"
        implementation "com.github.crosswall:Android-Coverflow:${viewPager_version}"
        implementation "com.squareup.okhttp3:logging-interceptor:3.4.0"
        implementation project(':sdkui')
        implementation 'com.github.ronaldsmartin:Material-ViewPagerIndicator:1.0.4'
        implementation 'com.google.android.gms:play-services-base:16.0.1'
        implementation 'com.google.android.gms:play-services-identity:16.0.0'
        implementation 'com.google.android.gms:play-services-auth:16.0.1'
        implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'
        implementation 'com.google.firebase:firebase-config:16.1.0'
        implementation 'com.google.firebase:firebase-core:16.0.4'
        implementation 'com.google.firebase:firebase-messaging:20.0.0'
    }
    apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 您正在使用需要 androidx 迁移的 firebase 库。
  • 您是否尝试过:在 Android Studio 上清理和重建?
  • @Gabriele Mariotti 我的项目运行良好,直到我尝试为 MaterialAlertDialog 添加依赖项。所以我不确定firebase是否会导致这个问题。
  • @DeepakJanardhanan 此外,材料组件库需要androidx libraries。
  • @GabrieleMariotti 你说的是正确的。是 Firebase 导致了这个问题。我把它降到 17.3.4 并且构建成功了。

标签: android android-manifest androidx


【解决方案1】:

我回答这个只是为了说明解决我的问题所采取的步骤。

  1. 我删除了 MaterialDesign 的 gradle 依赖项。
  2. 通过执行 File-> Invalidate Cache & restart 解决了缓存问题

由于 Firebase 在重新启动之前已更改为 20 版,因此问题仍然存在。

将 Firebase 版本降低到 17.3.4,这解决了所有问题。

【讨论】:

  • 感谢 Gabriele Mariotti 在我的问题下的评论让我能够解决问题。
【解决方案2】:

在您的清单文件中添加这些行。

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

清单文件

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

【讨论】:

  • 这不起作用。它只是导致发生额外的错误。我想提一下,我并没有尝试转换为 androidx,而只是删除了使用 androidx 的单个 gradle 条目。
【解决方案3】:

试试这个

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

如果您有任何 Maven 依赖项尚未迁移到 AndroidX 命名空间,当您在 gradle.properties 文件中将以下两个标志设置为 true 时,Android Studio 构建系统也会为您迁移这些依赖项:

android.useAndroidX=true
android.enableJetifier=true

在应用程序标签的清单文件中添加这些行。

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

【讨论】:

  • 这是一个 hack,并不能解决核心问题。相反,请确保更新所有库。我查看了build.gradle,并在 0.5 秒内找到了com.android.support:appcompat-v7,这在 AndroidX 中是不允许的。应该删除或替换这个和其他过时的库。
  • 使用最新版本更新代码总是更好的方法
  • 使用tools:replace 结合android:appComponentFactory 隐藏错误消息是一种技巧。你并没有解决核心问题,你只是在一个巨大的伤口上使用临时创可贴。我在这里找到了一个很好的定义:softwareengineering.stackexchange.com/questions/73334/…。
猜你喜欢
  • 1970-01-01
  • 2018-03-20
  • 1970-01-01
  • 2022-10-16
  • 2019-09-30
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 2018-09-20
相关资源
最近更新 更多