[英]Android Material and appcompat Manifest merger failed
I have next grade我有下一个年级
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.material:material:1.0.0-rc01'
}
But when I want to build app I get next log:但是当我想构建应用程序时,我会得到下一个日志:
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
Okey!好的! Go to manifest and do it:
转到清单并执行以下操作:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.chopcode.myapplication">
<application
tools:replace="android:appComponentFactory"
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/AppTheme">
</application>
</manifest>
Then I get this error in my Logcat:然后我在我的 Logcat 中收到此错误:
Manifest merger failed with multiple errors, see logs that I have Linked with it
I had similar problem.我有类似的问题。 Added two lines in
gradle.properties
file:在
gradle.properties
文件中添加了两行:
android.useAndroidX=true
android.enableJetifier=true
These two lines automatically resolved my dependency conflicts between google's files and third party dependencies.这两行自动解决了我的 google 文件和第三方依赖项之间的依赖项冲突。 Here's the link to follow: https://developer.android.com/topic/libraries/support-library/androidx-overview#new-project
这是要遵循的链接: https : //developer.android.com/topic/libraries/support-library/androidx-overview#new-project
You are using material library which is part of AndroidX .您正在使用属于AndroidX一部分的材料库。 If you are not aware of AndroidX, please go through this answer .
如果您不了解 AndroidX,请阅读此答案。
One app should use either AndroidX or old Android Support libraries.
一个应用程序应该使用 AndroidX 或旧的 Android 支持库。 That's why you faced this issue.
这就是你遇到这个问题的原因。
For example -例如 -
In your gradle, you are using在您的 gradle 中,您正在使用
com.android.support:appcompat-v7
(Part of old --Android Support Library--) com.android.support:appcompat-v7
(旧 --Android 支持库的一部分 --)com.google.android.material:material
(Part of AndroidX) (AndroidX build artifact of com.android.support:design
) com.google.android.material:material
(AndroidX 的一部分)( com.android.support:design
AndroidX 构建工件)So the solution is to use either AndroidX or old Support Library.所以解决方案是使用 AndroidX 或旧的支持库。 I recommend to use AndroidX, because Android will not update support libraries after version 28.0.0.
我推荐使用AndroidX,因为Android在28.0.0版本之后不会更新支持库。 See release notes of Support Library.
请参阅支持库的发行说明。
Just migrate to AndroidX.只需迁移到 AndroidX。 Here is my detailed answer to migrate to AndroidX.
这是我迁移到 AndroidX 的详细答案。 I am putting here the needful steps from that answer.
我把那个答案的必要步骤放在这里。
Before you migrate, it is strongly recommended to backup your project.在迁移之前,强烈建议备份您的项目。
Existing project
现有项目
New project
新项目
Put these flags in your gradle.properties
将这些标志放在你的
gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Check @ Library mappings for equal AndroidX package .检查@Library mappings for equal AndroidX package 。
Check @ Official page of Migrate to AndroidX检查@迁移到AndroidX的官方页面
In my case, this is working perfectly.. I have added below two line codes inside manifest file在我的情况下,这工作得很好..我在清单文件中添加了两行代码
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Credit goes to this answer .归功于这个答案。
in the gradle.properties
, just add below two scripts在
gradle.properties
,只需添加以下两个脚本
android.useAndroidX=true
android.enableJetifier=true
What was the reason ↓原因是什么↓
All packages in AndroidX live in a consistent namespace starting with the string androidx.
AndroidX 中的所有包都位于以字符串 androidx 开头的一致命名空间中。 The Support Library packages have been mapped into the corresponding androidx.* packages.
支持库包已映射到相应的 androidx.* 包中。 For a full mapping of all the old classes and build artifacts to the new ones, see the Package Refactoring page.
有关所有旧类和构建工件到新类的完整映射,请参阅包重构页面。
Please see the Package Refactoring page请参阅包重构页面
只需将依赖项内第一行和最后一行中的“rc01”更改为“alpha1”这对我有用
Just remove the android.support dependancy只需删除 android.support 依赖项
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Quoting From Material Guidelines引用材料指南
If you don't want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0-alpha3 dependency.
如果您还不想切换到新的 androidx 和 com.google.android.material 包,您可以通过 com.android.support:design:28.0.0-alpha3 依赖项使用 Material Components。
Note: You should not use the com.android.support and com.google.android.dependencies in your app at the same time.
注意:您不应在您的应用中同时使用 com.android.support 和 com.google.android.dependencies。
Just removing this dependency works fine只需删除此依赖项即可正常工作
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Here is complete dependencies example这是完整的依赖关系示例
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
As of Android P, the support libraries have been moved to AndroidX从 Android P 开始,支持库已移至AndroidX
Please do a refactor for your libs from this page .请从此页面重构您的库。
https://developer.android.com/topic/libraries/support-library/refactor https://developer.android.com/topic/libraries/support-library/refactor
Add these lines inside in AndroidManifest.xml file.在 AndroidManifest.xml 文件中添加这些行。
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Please go to Refactor->Migrate->Migrate to Android X.请去重构->迁移->迁移到Android X。
Please add this to your gradle.properties
file:请将此添加到您的
gradle.properties
文件中:
android.enableJetifier=true android.useAndroidX=true
And perform Sync.并执行同步。
just add these two lines of code to your Manifest file只需将这两行代码添加到您的清单文件中
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Follow these steps:按着这些次序:
Migrate to androidX
if it an existing project.如果它是现有项目,则迁移到
androidX
。 If it is new project add these two flags to Gradle.propeties
如果是新项目,将这两个标志添加到
Gradle.propeties
android.enableJetifier=true
android.useAndroidX=true
for more detail steps https://developer.android.com/jetpack/androidx or check this What is AndroidX?有关更多详细步骤https://developer.android.com/jetpack/androidx或检查此 什么是 AndroidX?
Only If you don't want to use androidx仅当您不想使用 androidx
So in my case, I am using a library that was using androidx but I am not using androidx so when I downgraded that library version the problem was resolved.所以就我而言,我使用的是一个使用 androidx 的库,但我没有使用 androidx,所以当我降级该库版本时,问题就解决了。
In my Case:在我的情况下:
implementation 'com.github.turing-tech:MaterialScrollBar:13.+'
the above-mentioned library makes problem 13.+ will automatically get a new version of the library which using androidx.上述库使问题 13.+ 将自动获取使用 androidx 的库的新版本。 So I downgraded library version to:
所以我将库版本降级为:
implementation 'com.github.turing-tech:MaterialScrollBar:13.2.5'
And the problem was resolved.问题得到了解决。
This issue mainly happened for old dependencies .这个问题主要发生在旧的依赖关系上。
There have 2 solution:有2个解决方案:
First one:第一:
Update all old dependencies
and ClassPaths from Project level gradle
files.更新所有
old dependencies
,从类路径和Project level gradle
文件。
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
Second one:第二个:
Your project Migrate to AndroidX
您的项目
Migrate to AndroidX
From Android Studio Menu -> Refanctor -> Migrate to AndroidX
从 Android Studio 菜单 -> Refanctor ->
Migrate to AndroidX
Thanks, let me know if anyone help from this answer.谢谢,如果有人从这个答案中得到帮助,请告诉我。
Finally found a quick and easy solution by adding two lines in the android/build.gradle
file.通过在
android/build.gradle
文件中添加两行,终于找到了一个快速简便的解决方案。
googlePlayServicesVersion = "16.+"
firebaseVersion = "17.6.0"
Please follow this 100% correct.请遵循此 100% 正确。
Its all about the library versions compatibility一切都与库版本兼容性有关
I was facing this strange bug couple of 2 hours.我面对这个奇怪的错误两个小时。 I resolved this error by doing these steps
我通过执行这些步骤解决了这个错误
hange your build.gradle dependencies into将您的 build.gradle 依赖项挂入
implementation 'com.google.android.gms:play-services-maps:17.0.0'
to到
implementation 'com.google.android.gms:play-services-maps:15.0.0'
All I did was go to the "Refactor" option on the top menu.我所做的只是转到顶部菜单上的“重构”选项。
Then select "Migrate to AndroidX"然后选择“迁移到AndroidX”
Accept to save the project as a zip file.接受以将项目另存为 zip 文件。
Please update Android Studio as well as Gradle to ensure no problems are encountered.请更新 Android Studio 和 Gradle 以确保不会遇到问题。
Create new project and compare your build.gradle files and replaced all创建新项目并比较您的 build.gradle 文件并替换所有
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
and other dependencies with the same as were in a new project someting like that和其他与新项目中相同的依赖项
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'androidx.core:core-ktx:1.0.0-alpha3'
And then fixed imports to use androidx in kotlin files.然后修复导入以在 kotlin 文件中使用 androidx。
1.Added these codes to at the end of your app/build.gradle: 1.在你的app/build.gradle的末尾添加这些代码:
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
// the above lib may be old dependencies version
}
2.Modified sdk and tools version to 28: 2.修改sdk和工具版本为28:
compileSdkVersion 28
buildToolsVersion '28.0.3'
targetSdkVersion 28
3.In your AndroidManifest.xml file, you should add two line: 3.在你的 AndroidManifest.xml 文件中,你应该添加两行:
<application
android:name=".YourApplication"
android:appComponentFactory="AnyStrings"
tools:replace="android:appComponentFactory"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
Or Simply或者干脆
If you do not intend to migrate to AndroidX follow the below steps如果您不打算迁移到 AndroidX,请按照以下步骤操作
First of all be sure to add this line in manifest tag首先确保在清单标签中添加这一行
xmlns:tools="https://schemas.android.com/tools"
Then add tools replace your suggested one in Android studio然后添加工具替换您在 Android Studio 中建议的工具
I had this same problem for three days.我有同样的问题三天。
It is like android wants us to either use Kotlin Or AndroidX, they are doing away with Android.就像 android 希望我们要么使用 Kotlin 要么使用 AndroidX,他们正在废除 Android。
But this is how I solved it.但这就是我解决它的方法。
NB: You must be using the latest Libraries (build.grudle file) in the latest stable version of android studio 3.4.1注意:您必须在 android studio 3.4.1 的最新稳定版本中使用最新的库(build.grudle 文件)
I don't know this is the proper answer or not but it worked for me我不知道这是否是正确的答案,但它对我有用
Increase Gridle Wrapper Property增加 Gridle Wrapper 属性
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
and Build Gridle to并构建 Gridle
classpath 'com.android.tools.build:gradle:3.4.2'
its showing error because of the version.由于版本,它的显示错误。
Try this尝试这个
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
Rebuild your project.重建你的项目。
I had the same error when working with Groupie (implementation 'com.xwray:groupie:2.3.0') 使用Groupie时出现相同的错误(实现'com.xwray:groupie:2.3.0')
I solved it by changing version to (implementation 'com.xwray:groupie:2.1.0') 我通过将版本更改为(实现'com.xwray:groupie:2.1.0')解决了该问题
In may case I didn't want to pass to androidX. 在某些情况下,我不想传递给androidX。 And I have to check my last changes.
而且我必须检查我的最后更改。 I figure out that the new component was --> lottie 2.8.0 So I downgrade it to: implementation 'com.airbnb.android:lottie:2.7.0'
我发现新组件是-> lottie 2.8.0,所以我将其降级为:实现'com.airbnb.android:lottie:2.7.0'
I hope that this may help someone. 我希望这可以帮助某人。
Change proguardFile in build.gradle (Module: app) to the following将 build.gradle (Module: app) 中的 proguardFile 更改为以下内容
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
instead of代替
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
This worked for me这对我有用
For solving this issue i would recommend to define explicitly the version for the ext variables at the android/build.gradle
at your root project为了解决这个问题,我建议在根项目的
android/build.gradle
中明确定义 ext 变量的版本
ext {
googlePlayServicesVersion = "16.1.0" // default: "+"
firebaseVersion = "15.0.2" // default: "+"
// Other settings
compileSdkVersion = <Your compile SDK version> // default: 23
buildToolsVersion = "<Your build tools version>" // default: "23.0.1"
targetSdkVersion = <Your target SDK version> // default: 23
supportLibVersion = "<Your support lib version>" // default: 23.1.1
}
reference https://github.com/zo0r/react-native-push-notification/issues/1109#issuecomment-506414941参考https://github.com/zo0r/react-native-push-notification/issues/1109#issuecomment-506414941
我也面临同样的问题,对于您的 android studio,您只需更改 android Gradle 插件版本 3.3.2,Gradle 版本为 5.1.1
I have next grade我下一年级
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.material:material:1.0.0-rc01'
}
But when I want to build app I get next log:但是,当我要构建应用程序时,我会收到下一条日志:
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
Okey!哎呀! Go to manifest and do it:
进行清单并执行以下操作:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.chopcode.myapplication">
<application
tools:replace="android:appComponentFactory"
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/AppTheme">
</application>
</manifest>
Then I get this error in my Logcat:然后我在Logcat中收到此错误:
Manifest merger failed with multiple errors, see logs that I have Linked with it
go to manifest file delete this line 转到清单文件删除此行
xmlns:tools="http://schemas.android.com/tools"
and add this line 并添加此行
xmlns:android="http://schemas.android.com/apk/res/android"
if this works do upvote 如果这项工作做upvote
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.