Android Studio初学者AndroidManifest.xml资源链接失败报错求助
报错根因
Android resource linking failed、unexpected element found报错来自清单文件语法错误:
- 文件开头存在两个重复的
<manifest>根标签,Android清单文件仅允许一个顶层根节点,重复声明根节点属于非法语法 - 文件末尾缺失
</manifest>根节点闭合标签 - 手动添加的
tools:ignore="WrongManifestParent"属于无效兜底规则,没有解决根本问题
修复方案
直接按以下步骤修改AndroidManifest.xml:
- 删除开头单独占行的多余标签:
<manifest xmlns:tools="http://schemas.android.com/tools"> - 将
xmlns:tools命名空间声明合并到保留的唯一<manifest>标签中 - 在文件最末尾补上缺失的
</manifest>闭合标签 - 清理项目后重新构建即可消除报错
修复后可直接使用的完整清单代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.MyPlace"> <uses-permission android:name="android.permission.INTERNET" /> <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.TollGate"> <activity android:name=".PlaceListActivity" android:exported="false" /> <activity android:name=".AddPlacesActivity" android:exported="false" /> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
后续操作
替换完文件内容后,在Android Studio顶部菜单栏依次执行:
- 点击
Build > Clean Project等待清理完成 - 点击
Build > Rebuild Project重新构建项目
构建完成后报错会自动消失。
内容的提问来源于stack exchange,提问作者Tahir Aziz
相关产品推荐
相关产品推荐

