Android Studio出现Manifest merger failed with multiple errors错误如何解决
问题原因
该报错属于Android清单文件合并冲突,本质是项目同时引入了AndroidX系列依赖(androidx.core:core:1.5.0)和旧版Android Support支持库依赖(com.android.support:support-compat:28.0.0),两个库对appComponentFactory属性的定义不一致,导致合并失败。
解决方案
提供两种修复方式,可按需选择:
方案1:临时快速修复(直接按系统提示配置覆盖冲突)
操作步骤如下:
- 在
AndroidManifest.xml的<manifest>根节点新增tools命名空间声明 - 在
<application>节点添加冲突属性覆盖配置
修改后的完整清单文件内容如下:
<?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="com.kelompok22.veterinarycare"> <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/Theme.Transparent" tools:replace="android:appComponentFactory" android:appComponentFactory="androidx.core.app.CoreComponentFactory"> <activity android:name=".RegisterActivity"></activity> <activity android:name=".StartActivity" /> <activity android:name=".LoginActivity" /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
修改完成后重新构建项目即可解决当前报错。
方案2:彻底修复(全项目迁移AndroidX,避免后续同类冲突)
旧版Support库已经停止维护,后续所有新特性都只会在AndroidX上更新,建议直接迁移:
- 点击Android Studio顶部菜单栏
Refactor > Migrate to AndroidX - 等待依赖扫描完成后,点击
Do Refactor执行全项目迁移 - 迁移完成后依次执行
Build > Clean Project、Build > Rebuild Project清理重建即可
内容的提问来源于stack exchange,提问作者Rahadian Nugraha
相关产品推荐
相关产品推荐

