You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Flutter Android编译报错:需显式指定android:exported属性

修复Android 12+下Flutter Local Notifications的Manifest编译错误

错误原因

Android 12(API 31)及更高版本的应用,所有带有intent-filter的组件(如receiver、activity)必须显式声明android:exported属性(值为true或false)。你遇到的问题是flutter_local_notifications插件自带的ScheduledNotificationBootReceiver组件未声明该属性,导致Manifest合并时触发编译错误。

修复步骤

方法一:在项目Manifest中补充属性(推荐,不受插件更新影响)

  1. 打开项目路径下的android/app/src/main/AndroidManifest.xml文件
  2. 在<application>标签内部添加以下代码,显式为目标Receiver指定android:exported属性:
<receiver
    android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
    android:exported="false"
    tools:node="merge">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
    </intent-filter>
</receiver>
  • tools:node="merge"确保项目配置与插件Manifest的配置合并,不会覆盖原有intent-filter
  • android:exported="false"表示该Receiver仅能被本应用内部调用,符合安全规范

方法二:检查并升级SDK版本(必要前提)

确保项目的编译和目标SDK版本至少为31(对应Android 12),打开android/app/build.gradle文件修改:

android {
    compileSdkVersion 34 // 建议使用最新稳定版,最低31
    defaultConfig {
        targetSdkVersion 34 // 最低31
    }
}

完成以上操作后,重新执行Flutter编译部署命令即可解决错误。

内容的提问来源于stack exchange,提问作者Spandan Halder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 23:31:02