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

Flutter项目Android12安装失败及不兼容包排查求助

Android 12 下 Flutter 项目安装失败解决及依赖包排查方法

一、解决 flutter_local_notifications 组件的导出属性问题

你遇到的报错是因为flutter_local_notifications包里的ScheduledNotificationBootReceiver广播接收器没显式声明android:exported属性,Android 12(API 31+)要求所有带intent filter的组件必须加这个属性。你自己的Manifest加了没用,得覆盖依赖包里的组件配置:

  1. 打开android/app/src/main/AndroidManifest.xml
  2. 在<application>标签里添加这段配置,强制给该接收器加上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>

另外更省心的办法是直接升级flutter_local_notifications到最新版,新版本一般已经适配了Android 12的要求,执行命令升级:

flutter pub upgrade flutter_local_notifications

二、排查不兼容 Android 12 的 Flutter 依赖包

1. 查看合并后的AndroidManifest文件

Android会把所有依赖包的Manifest合并成最终文件,你可以直接找这个文件定位问题:

  • 先执行flutter build apk --debug构建项目
  • 去这个路径找合并后的Manifest:android/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml
  • 搜索所有带<intent-filter>的<activity>、<receiver>、<service>组件,没加android:exported的就是问题来源

2. 检查依赖版本状态

  • 执行flutter pub outdated,看哪些依赖是旧版本,优先查这些包的更新日志,确认是否有Android 12适配说明
  • 查看对应包的Changelog,确认是否提到API 31适配内容

3. 逐个排除可疑依赖

如果找不到问题,就临时移除依赖测试:

  • 注释掉pubspec.yaml里的一个依赖,执行flutter pub get
  • 再尝试flutter run到Android 12设备,能运行的话,刚移除的就是不兼容的包,要么升级要么换替代包

4. 确认targetSdkVersion配置

检查android/app/build.gradle里的targetSdkVersion,必须设为31或更高:

android {
    defaultConfig {
        targetSdkVersion 33 // 至少31,建议用最新稳定版本
    }
}

内容的提问来源于stack exchange,提问作者許子霆

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 13:12:14