Flutter集成本地推送通知Android编译报错:需指定android:exported
解决Flutter本地通知Android编译Manifest合并错误
错误根源是flutter_local_notifications插件的ScheduledNotificationBootReceiver组件带有Intent Filter,但未显式指定android:exported属性,而Android 12及以上版本要求所有带有Intent Filter的组件必须明确设置该属性。你之前设置为false无效是因为该接收器需要接收系统广播(如开机完成),必须设为true才能正常工作。
解决方案
在你的AndroidManifest.xml的<application>标签内,手动添加该接收器的声明并显式指定android:exported="true":
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.planer.todo"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application android:label="Done" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> <!-- 手动添加的接收器声明,解决exported属性问题 --> <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> </intent-filter> </receiver> <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" android:background="true" android:showWhenLocked="true" android:turnScreenOn="true"> <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> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>
补充说明
- 该接收器负责在设备开机或应用更新后重新调度本地通知,必须允许系统触发,因此
android:exported必须设为true。 - 手动声明后,Manifest合并工具会优先使用你显式设置的属性,覆盖插件默认的未声明状态,从而解决编译错误。
内容的提问来源于stack exchange,提问作者Liam
相关产品推荐
相关产品推荐

