Flutter中AndroidManifest.xml报错:uses-permission元素缺少name属性
解决AndroidManifest.xml中uses-permission缺少name属性的问题
你遇到的报错是因为AndroidManifest.xml里存在未指定android:name属性的<uses-permission>标签——虽然你贴出的代码里的INTERNET权限声明是合法的,但大概率是flutter_launcher_icons插件在生成或替换文件时,意外插入了空的权限标签。
解决步骤:
- 打开
android/app/src/main/AndroidManifest.xml,仔细检查整个文件,找到所有类似<uses-permission/>的空标签并删除。 - 确保所有保留的
<uses-permission>标签都带有合法的android:name属性,比如你代码里的:<uses-permission android:name="android.permission.INTERNET"/> - 重新执行图标生成命令:
flutter pub run flutter_launcher_icons:main - 清理项目缓存并重建,避免残留问题:
flutter clean flutter build apk
附你提供的AndroidManifest.xml代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:label="authsec_flutter" 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: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> <uses-permission android:name="android.permission.INTERNET"/> </manifest>
内容的提问来源于stack exchange,提问作者akash_zamnani
相关产品推荐
相关产品推荐

