Android12+应用报错:需为指定Receiver显式设置android:exported
解决Flutter Android 12+中
ScheduledNotificationBootReceiver需显式指定android:exported的问题 问题描述
开发面向Android 12及更高版本的Flutter应用时,编译报错:
针对元素
<receiver#com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver>,必须显式指定android:exported。
Android 12及以上版本强制要求:当组件(如Receiver)定义了intent-filter时,必须显式设置android:exported的布尔值,明确组件是否允许外部应用交互。
解决步骤
- 打开项目路径下的
android/app/src/main/AndroidManifest.xml文件 - 在Manifest中添加或修改对应的
<receiver>配置,显式声明android:exported属性:- 若接收器需要接收系统或外部应用的Intent(比如监听开机完成事件),设置
android:exported="true" - 若仅用于应用内部交互,设置
android:exported="false"
- 若接收器需要接收系统或外部应用的Intent(比如监听开机完成事件),设置
- 示例配置代码:
<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>
如果使用的是flutter_local_notifications库,也可以优先检查库版本是否已适配Android 12,但直接在本地Manifest中显式声明该属性是最直接的修复方式。
内容的提问来源于stack exchange,提问作者Louay Elaroui pro
相关产品推荐
相关产品推荐

