【问题标题】:Android X: tools:replace specified at line: for attribute, but no new value specifiedAndroid X:tools:replace 在 line: for 属性中指定,但没有指定新值
【发布时间】:2019-04-15 13:40:19
【问题描述】:

我在这个网站上尝试了很多解决方案,但问题仍然没有解决。问题是由于 Android X 库造成的。当我添加 Android X 时,这个问题得到了解决,但它打开了新问题。如何解决这个问题?

之前这个错误出现了:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] 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:19:5-142:19 to override.

我添加tools:replace="android:appComponentFactory"后,出现了这个错误:

 java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
at com.android.builder.core.AndroidBuilder.mergeManifestsForApplication(AndroidBuilder.java:540)    
at com.android.build.gradle.tasks.MergeManifests.doFullTaskAction(MergeManifests.java:173)

合并错误(在 Android 清单中):

错误:工具:替换在第 2 行指定的属性 android:appComponentFactory,但没有指定新值 app main 清单(此文件),第 1 行

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    package="com.example"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:replace="allowBackup, android:appComponentFactory"
    android:allowBackup="false">

    ...

    <application
        android:name="com.example"
        android:icon="@mipmap/icon"
        android:debuggable="true"
        android:hardwareAccelerated="false"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:allowBackup="false"
        tools:ignore="GoogleAppIndexingWarning,HardcodedDebugMode">
       ...

【问题讨论】:

  • 你检查过这个答案吗:stackoverflow.com/a/54825603/1318946
  • 你有没有机会使用firebase?如果是,最新版本在 android X 上,因此错误
  • @Ggriffo 不。我没有使用 Firebase。
  • 当我的项目未迁移到 androidX 时遇到此错误,我尝试同步 CameraX 库。迁移后一切正常。

标签: java android android-gradle-plugin android-manifest androidx


【解决方案1】:

我认为您正在迁移到 AndroidX 库。

将下面的行添加到 gradle.properties 文件

android.useAndroidX=true
android.enableJetifier=true

从清单中删除 tools:replace="android:appComponentFactory"

android.support.v7.app.AppCompatActivity 替换为androidx.appcompat.app.AppCompatActivity

Migrating to AndroidX

【讨论】:

  • 我应该在哪里替换 android.support.v7.app.AppCompatActivity ?
  • @Lucky_girl 你必须使用android.support.v7.app.AppCompatActivity。这意味着您必须已创建此活动的子活动。将它们替换为androidx.appcompat.app.AppCompatActivity
  • 我做的一切都是一样的,但得到了这个错误:Manifest merger failed : Attribute application@appComponentFactory value=(whateverString) from AndroidManifest.xml:26:9-53 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 &lt;application&gt; element at AndroidManifest.xml:23:5-149:19 to override.
  • @AliAkram 当您的应用(未针对 AndroidX 配置)使用实际使用 AndroidX 的库时会发生这种情况。您应该做的是查看库发布历史记录,看看在该库切换到 AndroidX 之前是否有发布。最后为自己编写一个工作项,将您的应用程序转换为 AndroidX - 根据项目的大小,这可能需要相当长的时间。
【解决方案2】:

您可以尝试添加:

android:appComponentFactory="android.support.v4.app.CoreComponentFactory"

到清单中的标签&lt;application &gt;

【讨论】:

  • 这不是一个好的解决方案,因为它强制使用 API 级别 28 或更高版本
  • 谢谢,这对我有用,但即使在生产中也可以继续使用它吗?
【解决方案3】:

我在我的项目中遇到了同样的错误,我已经解决了 你可以试试

Android Studio > 重构 > 迁移到 AndroidX

【讨论】:

  • 不,它会自动修复所有导入
【解决方案4】:

就我而言,我更新了 Firebase 和播放服务依赖项,导致了这个问题。

恢复了依赖更新,错误消失了

似乎最新的 Firebase 和 Play Service 依赖项与 androidx 兼容。

【讨论】:

    【解决方案5】:

    这种情况经常发生,因为您同时使用了 Androidx 库支持库。一些 3rd-party 库可能包含支持库,而其他 3rd-party 库可能包含 Androidx 库,这也可能导致此问题。如果你的 PC 有 gradle 环境,在 Android Studio 的终端中尝试“gradlew :app:dependencies”命令,该命令将列出你项目的所有库,包括 3rd-party 库,并查看哪个库或框架使用了 Androidx 库和这不是。然后尝试升级使用支持库的旧库,这个问题应该会消失。

    【讨论】:

      【解决方案6】:

      就我而言,由于我使用的 firebase 版本,我遇到了问题。 降级 firebase 版本对我有帮助。

      实现 'com.crashlytics.sdk.android:crashlytics:2.10.1' 实施 'com.google.firebase:firebase-core:16.0.6'

      【讨论】:

        【解决方案7】:

        您只需在 gradle.properties 文件中添加此代码

        android.useAndroidX=true
        android.enableJetifier=true
        

        【讨论】:

        • 这有什么帮助?
        • 我在项目中没有这个文件。我有一个 3 或 4 年的应用程序并尝试设置它
        • 新建一个项目,复制新项目中的所有旧文件
        【解决方案8】:

        我在&lt;application&gt; 标签内添加了以下行

        tools:replace="android:appComponentFactory" android:appComponentFactory="android.support.v4.app.CoreComponentFactory"

        gradle.properties 文件中的以下行

        android.useAndroidX=true android.enableJetifier=true

        重建您的项目。

        【讨论】:

          【解决方案9】:

          迁移到 android x

          在标签内添加以下行

              tools:replace="android:appComponentFactory"
              android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
          

          然后在 gradle.properties 文件中添加以下行

            android.useAndroidX=true
            android.enableJetifier=true
          

          重建您的项目。

          【讨论】:

            【解决方案10】:

            以这种方式配置您的清单应用程序标签

            <application
                    android:fullBackupContent="true"
                    android:usesCleartextTraffic="true"
                    tools:targetApi="m"
                    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/Theme.Media">
            

            【讨论】:

              【解决方案11】:

              在我的情况下,我有问题

              tools:replace="android:usesCleartextTraffic"
              

              我已经用过AndroidX,我在gradle.properties中已经有了这些属性

              android.useAndroidX=true
              android.enableJetifier=true
              

              问题是我忘记将值设置为true(或者它可以是false,取决于你的情况)

              <application
                      android:label="myApp"
                      tools:replace="android:usesCleartextTraffic"
                      android:usesCleartextTraffic="true"> // I forget this line
              

              【讨论】:

                猜你喜欢
                • 2015-08-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2014-08-20
                • 2019-09-25
                • 2011-01-31
                • 1970-01-01
                相关资源
                最近更新 更多