Flutter应用迁移至Android 12:android:export属性配置位置咨询
Android 12迁移中android:export属性的正确配置方案
你的配置问题出在两个核心点:
- application标签无需android:exported属性:该属性仅针对Activity、Service等四大组件生效,在application层级声明属于无效配置,会触发编译报错。
- 带intent-filter的Service必须显式声明android:exported:Android 12及以上版本强制要求,所有包含
<intent-filter>的组件必须明确指定android:exported属性,否则编译失败。
以下是修正后的完整AndroidManifest.xml代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.atgapp.atgapp"> <application android:label="atgapp" android:name="${applicationName}" android:icon="@mipmap/icono"> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/icon" /> <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"> <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> <intent-filter> <action android:name="FLUTTER_NOTIFICATION_CLICK" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <meta-data android:name="flutterEmbedding" android:value="2" /> <service android:name=".MyFirebaseMessagingService" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> </application> </manifest>
关键修改说明:
- 移除了
<application>标签上的android:exported="true"属性,消除无效配置。 - 给
<service>标签添加android:exported="true"属性:由于该Service配置了接收Firebase消息的intent-filter,需要允许外部服务(Firebase)调用,因此设为true。
内容的提问来源于stack exchange,提问作者Albert
相关产品推荐
相关产品推荐

