清理Flutter依赖后执行flutter pub get报错:AndroidManifest.xml解析失败
修复Flutter中AndroidManifest.xml解析失败的问题
执行flutter pub get时触发错误:
解析本地文件'C:\Users\prashant\Desktop\bpls\android\app\src\main\AndroidManifest.xml'失败,请确保Android清单是有效的XML文档并重试。
对应的AndroidManifest.xml代码如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.bpls"> <uses-permission android:name="android.permission.INTERNET"/> <!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> --> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.VIBRATE" /> <application android:label="bpls" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:showWhenLocked="true" android:turnScreenOn="true" android:windowSoftInputMode="adjustResize"> <!-- Specifies an Android theme to apply to this Activity as soon as the Android process has started. This theme is visible to the user while the Flutter UI initializes. After that, this theme continues to determine the Window background behind the Flutter UI. --> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>
修复步骤
排查XML语法细节:
从代码看整体标签闭合正常,但需确认:- 注释无语法错误:你注释的权限标签写法正确,无遗漏
-->结束标记 - 调整属性空格:
android:theme="@style/LaunchTheme"与android:configChanges之间仅单个空格,虽XML允许,但建议换行分隔,避免解析器误判,修改为:android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
- 注释无语法错误:你注释的权限标签写法正确,无遗漏
清理项目缓存并重建:
- 执行命令
flutter clean清除项目缓存 - 删除
android/.gradle目录(若存在) - 重新运行
flutter pub get
- 执行命令
验证文件有效性:
- 用Android Studio打开该文件,IDE会自动高亮XML语法错误(如未闭合标签、非法字符)
- 检查文件是否含隐藏特殊字符(如全角空格、不可见字符),这类字符易导致解析失败
确认文件编码:
确保AndroidManifest.xml使用UTF-8编码,避免编码问题引发解析错误
内容的提问来源于stack exchange,提问作者Sujan Rijal
相关产品推荐
相关产品推荐

