java – Android X:工具:替换为line:for属性,但没有指定新值

我在这个网站上尝试了很多解决方案,但问题仍未解决.问题是由于Android X库.当我添加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.

我添加工具后: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 Manifest中):

Error: tools:replace specified at line:2 for attribute
android:appComponentFactory, but no new value specified app main
manifest (this file), line 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">
       ...

解决方法:

我认为你正在迁移到AndroidX库.

将以下行添加到gradle.properties文件中

android.useAndroidX=true
android.enableJetifier=true

从清单中删除工具:replace =“android:appComponentFactory”.

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

Migrating to AndroidX

上一篇:AndroidX之前和之后的DialogPreference之间的区别


下一篇:androidx.appcompat.app.AppCompatActivity未实现LifecycleOwner