尝试使用
flutter run
命令运行 Flutter 应用程序会产生以下错误:
No `<meta-data android:name="flutterEmbedding" android:value="2"/>` in "..\src\main\AndroidManifest.xml"
这是我的
AndroidManifest.xml
文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coding.informer.simple_material_app">
<uses-permission android:name="android.permission.INTERNET"/>
<application android:name="${applicationName}" android:label="simple_material_app" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
我知道错误消息提供了一个明显的解决方案,但我想在这里发布我的答案,以便其他遇到此错误的人可以快速解决它。
问题是
AndroidManifest.xml
文件缺少必需的 <meta-data android:name="flutterEmbedding" android:value="2"/>
标签。像这样添加:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coding.informer.simple_material_app">
<uses-permission android:name="android.permission.INTERNET"/>
<meta-data android:name="flutterEmbedding" android:value="2"/>
<application android:name="${applicationName}" android:label="simple_material_app" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
所以你的清单填写将如下所示:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coding.informer.simple_material_app">
<uses-permission android:name="android.permission.INTERNET"/>
<application android:name="${applicationName}" android:label="simple_material_app" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
在 GitHub 存储库的 udemy 课程中运行测试代码时遇到同样的问题dicee-flutter
如你所见,我的flutter版本是3.16.9
flutter --version
Flutter 3.16.9 • channel stable • https://github.com/flutter/flutter.git
我的dart版本是3.2.6
dart --version
Dart SDK version: 3.2.6 (stable) (Wed Jan 24 13:41:58 2024 +0000) on "macos_x64"
由于错误表明您在 AndroidManifest.xml 中缺少所述元数据标记。
所以请添加一个。
<meta-data
android:name="flutterEmbedding"
android:value="2" />