Flutter集成flutter_local_notifications与FCM时AndroidManifest编译报错
解决flutter_local_notifications针对Android 12+的exported属性编译错误
你之前把android:exported加在MainActivity上是没用的,错误提示里的ScheduledNotificationBootReceiver是flutter_local_notifications库自带的广播接收器,需要给这个组件单独设置exported属性,步骤如下:
- 打开项目的
android/app/src/main/AndroidManifest.xml文件 - 找到或添加
ScheduledNotificationBootReceiver的声明,显式指定android: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>
- 同时,为了避免其他潜在编译错误,建议给同库的
ScheduledNotificationReceiver也添加exported属性:
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" android:exported="false"/>
注意:
android:exported="true"是因为该接收器需要监听系统发出的开机完成广播,必须允许接收外部广播- 如果你的flutter_local_notifications版本较旧,建议先升级到最新稳定版,新版本可能已经默认配置了该属性,无需手动添加
内容的提问来源于stack exchange,提问作者ayush
相关产品推荐
相关产品推荐

