Flutter项目Gradle构建失败:android:exported未明确指定
解决Android 12+环境下flutter_local_notifications的assembleDebug失败问题
方案1:升级到最新稳定版flutter_local_notifications
- 打开项目根目录的
pubspec.yaml,将flutter_local_notifications的版本指定为当前最新稳定版,示例:dependencies: flutter_local_notifications: ^16.1.0 # 替换为实际最新稳定版本号 - 执行命令
flutter pub get完成依赖更新。
方案2:手动在AndroidManifest.xml中配置exported属性
若升级包后仍报错,直接在android/app/src/main/AndroidManifest.xml中添加对应receiver配置,覆盖默认设置:
<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> <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" android:exported="false"/>
说明:
ScheduledNotificationBootReceiver带有intent filter,需设置android:exported="true";ScheduledNotificationReceiver无intent filter,设置为false即可。
方案3:处理废弃API提示
如果控制台出现废弃API警告,可调整Android编译配置:
- 打开
android/app/build.gradle,提升编译和目标SDK版本:
android { compileSdkVersion 33 defaultConfig { targetSdkVersion 33 } }
- 打开
android/build.gradle,适配gradle插件版本:
dependencies { classpath 'com.android.tools.build:gradle:7.4.2' // 与compileSdk 33版本匹配 }
最后验证操作
- 执行
flutter clean清除项目缓存 - 重新运行
flutter run或执行assembleDebug任务
内容的提问来源于stack exchange,提问作者zzangzz
相关产品推荐
相关产品推荐

