java - Android X : tools:replace specified at line: for attribute, 但未指定新值

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

我在这个网站上尝试了很多解决方案,但问题仍然没有解决。问题是由于 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 list 中):

Error: tools:replace specified at line:2 for attribute android:appComponentFactory, but no new value specified app main manifest (this file), line 1

list :

<?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">
       ...

最佳答案

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

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

android.useAndroidX=true
android.enableJetifier=true

从 list 中删除 tools:replace="android:appComponentFactory"

在 Activity 中替换从 android.support.v7.app.AppCompatActivityandroidx.appcompat.app.AppCompatActivity 的导入。在项目中使用替换来加快重构过程。

Migrating to AndroidX

关于java - Android X : tools:replace specified at line: for attribute, 但未指定新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53268865/

相关文章:

android - 任务 : Error while merging dex archives 的 NativeScript 执行失败

java - Gradle 同步失败 : A problem occurred configuring project ':lib'

android - 在 gradle 中重构 Maven block

java - Java 中的字符串池的行为是否类似于 LRU 缓存?

android - Firebase 远程配置安全

Java - 为什么 Map.put() 覆盖而 Set.add() 不覆盖?

Android 图像按钮淡入淡出

Android 多个 dex 文件定义 Lcom/google/android/gms/common/api/zza

java - 用 Java 编写响应处理程序

java - 找不到任何支持 AES/GCM/NoPadding 的提供商