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

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编译配置:

  1. 打开android/app/build.gradle,提升编译和目标SDK版本:
android {
    compileSdkVersion 33

    defaultConfig {
        targetSdkVersion 33
    }
}
  1. 打开android/build.gradle,适配gradle插件版本:
dependencies {
    classpath 'com.android.tools.build:gradle:7.4.2'  // 与compileSdk 33版本匹配
}

最后验证操作

  • 执行flutter clean清除项目缓存
  • 重新运行flutter run或执行assembleDebug任务

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 13:24:53