这个问题在这里已有答案:
使用Google所谓的Material Design 2.0需要您添加
implementation 'com.google.android.material:material:1.0.0-rc01'
在应用程序Gradle中也包括
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
这显示了冲突
这是日志所说的内容
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-rc02] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0-rc01] 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.
即使在将其添加到Manifest之后,它也显示Manifest Merger因多次错误而失败
现在这个错误很常见:
当我们得到这种类型的错误时:更新库并提供AndroidX的使用,但我们使用旧的。
您可以按照以下步骤解决此问题:
使用Android Studio 3.2及更高版本,您可以通过从菜单栏中选择Refactor> Migrate to AndroidX,快速迁移现有项目以使用AndroidX。
注意:要迁移不使用任何需要转换的依赖项的第三方库的现有项目,可以将
android.useAndroidX
标志设置为true,将android.enableJetifier
标志设置为false。
这一步将自动完成一切所有答案都应该手动完成
即使您遇到任何其他错误,如运行时构建失败,那么:
要么
希望它对所有人都有帮助。谢谢。
要解决此问题,您必须添加工具命名空间并将建议的属性应用于IDE建议的应用程序元素。
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="your.package.uri">
<application
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"
tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx">
在build.gradle文件中用androidx替换所有android依赖项。
例如:
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'androidx.annotation:annotation:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
建议:在
tools:replace="android:appComponentFactory"
:5:5-19:19中添加'AndroidManifest.xml
'元素以覆盖。
如果您添加了tools:replace="android:appComponentFactory"
并且仍然通过修复它而遇到麻烦,请创建一个新项目,将代码和相同的依赖项复制粘贴到那里。在那之后,我希望它应该是固定的。
如果它没有解决问题,请尝试添加以下两个:
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
在AndroidManifest.xml
> <application
标签当然。
替换依赖项:
implementation 'com.google.android.material:material:1.0.0-rc01'
至:
implementation 'com.android.support:design:28.0.0'
我也有这个问题,我按照官方文档迁移到AndroidX。只能通过Refactor - >迁移到AndroidX。
Migration to AndroidX Official Docs
希望这可以帮助。
尝试:替换rc01 >> alpha1。它对我有用!
取消选择即时运行对我有用。不确定它是否对每个人都有帮助。