Java Android X:tools:replace 指定于 line: for 属性,但未指定新值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53268865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android X: tools:replace specified at line: for attribute, but no new value specified
提问by Malwinder Singh
I have tried many solutions on this website but still, the problem is not solved. The issue is due to Android X library. When I added Android X, this issue was resolved but it opened up new issue. How to fix this issue?
我在这个网站上尝试了很多解决方案,但仍然没有解决问题。该问题是由于 Android X 库造成的。当我添加 Android X 时,这个问题得到了解决,但它开辟了新的问题。如何解决这个问题?
Earlier this error was coming:
早些时候这个错误来了:
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.
After I added tools:replace="android:appComponentFactory"
, this error is came:
添加后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)
Merging Error (in Android Manifest):
合并错误(在 Android 清单中):
Error: tools:replace specified at line:2 for attribute android:appComponentFactory, but no new value specified app main manifest (this file), line 1
错误:工具:在第 2 行为属性 android:appComponentFactory 指定替换,但没有指定新值应用主清单(此文件),第 1 行
Manifest:
显现:
<?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">
...
回答by Akshay
I think you are migrating to AndroidX libs.
我认为您正在迁移到 AndroidX 库。
Add below lines to gradle.propertiesfile
将以下几行添加到gradle.properties文件
android.useAndroidX=true
android.enableJetifier=true
Remove tools:replace="android:appComponentFactory"
from manifest.
tools:replace="android:appComponentFactory"
从清单中删除。
Replace android.support.v7.app.AppCompatActivity
to androidx.appcompat.app.AppCompatActivity
替换android.support.v7.app.AppCompatActivity
为androidx.appcompat.app.AppCompatActivity
回答by Gabriel Aguirre
You can try adding:
您可以尝试添加:
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
To the tag <application >
in your manifest.
到<application >
清单中的标签。
回答by shailesh
回答by codepeaker
In my case, I had updated Firebase and play services dependency, result in this issue.
就我而言,我更新了 Firebase 和播放服务依赖项,导致了这个问题。
Reverted back the dependency updates and the error vanished
恢复依赖项更新并且错误消失了
Seems that the latest Firebase and Play Service dependencies are compatible with androidx.
似乎最新的 Firebase 和 Play Service 依赖项与androidx兼容。
回答by komaki
It often happened because you used Androidx librariesand support librariesat the same time. Some 3rd-party libraries may contain support libraries and other 3rd-party libraries may contain Androidx libraries, this can also lead this problem. If you have gradle environment in you PC, try "gradlew :app:dependencies" command in the terminal of Android Studio, this command will list all libraries including 3rd-party libraries of your project, and see which library or framework used Androidx libraries and which not. Then try to upgrade old libraries used support libraries, and this problem should disappear.
经常发生这种情况是因为您同时使用了Androidx 库和支持库。某些 3rd 方库可能包含支持库,而其他 3rd 方库可能包含 Androidx 库,这也会导致此问题。如果你的电脑有 gradle 环境,在 Android Studio 的终端中尝试“gradlew :app:dependencies”命令,这个命令会列出你项目的所有库,包括 3rd-party 库,看看哪个库或框架使用了 Androidx 库和哪个不是。然后尝试升级旧库使用的支持库,这个问题应该会消失。
回答by rishabh gupta
In my case, i was facing problem because of the firebase version i was using. Downgrading the firebase version helped me.
就我而言,由于我使用的 firebase 版本,我遇到了问题。降级 firebase 版本对我有帮助。
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation 'com.google.firebase:firebase-core:16.0.6'
实现 'com.crashlytics.sdk.android:crashlytics:2.10.1' 实现 'com.google.firebase:firebase-core:16.0.6'
回答by Rasoul Miri
you need just add this code in gradle.propertiesfile
您只需在gradle.properties文件中添加此代码
android.useAndroidX=true
android.enableJetifier=true
回答by Nikhil Lotke
I added below lines inside <application>
tag
我在<application>
标签内添加了以下几行
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
below lines inside gradle.properties file
在 gradle.properties 文件中的下面几行
android.useAndroidX=true
android.enableJetifier=true
android.useAndroidX=true
android.enableJetifier=true
Rebuild your project.
重建你的项目。
回答by Nomuoja Oghenemaro
migrate to android x
迁移到 android x
add below lines inside tag
在标签内添加以下几行
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
then also add below lines inside gradle.properties file
然后还在 gradle.properties 文件中添加以下几行
android.useAndroidX=true
android.enableJetifier=true
Rebuild your project.
重建你的项目。