新Gradle声明式插件格式下Flutter本地通知配置失败求助
Flutter Local Notifications 适配新版项目结构配置指南
一、AndroidManifest.xml 配置补充
你的清单文件已包含基础权限,直接将以下组件配置添加到 <application> 标签内部即可:
<!-- 处理定时通知与开机自启的广播接收器 --> <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" android:exported="false" /> <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver" android:exported="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/> </intent-filter> </receiver> <!-- Android 8.0+ 必需的通知渠道服务 --> <service android:name="com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsService" android:exported="false"/> <service android:name="com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsBackgroundService" android:exported="false"/>
若仍报找不到类错误,执行
flutter pub upgrade flutter_local_notifications确保依赖为最新稳定版,再执行flutter clean && flutter pub get清除缓存。
二、build.gradle 依赖区块处理
新版 Flutter 项目采用统一依赖管理,dependencies 区块可能被隐藏或需要手动添加:
- 打开
android/app/build.gradle,确认开头的插件配置完整:
plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" }
- 若文件中无
dependencies区块,直接在文件末尾新增:
dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // 按需添加 AndroidX 依赖(如通知渠道相关) implementation "androidx.core:core-ktx:1.10.1" }
注:
flutter pub add flutter_local_notifications会自动处理插件依赖,无需手动添加插件本身的依赖项。
三、常见问题排查
- 类找不到错误:
- 确认
android:name中的类路径与插件版本匹配,避免版本不兼容 - 检查
flutterEmbedding="2"是否存在于清单文件中(新版 Flutter 自动注册插件依赖此配置)
- 确认
- 通知不显示:
- Android 8.0+ 需在代码中主动创建通知渠道
- 调用
permission_handler包申请通知权限:
import 'package:permission_handler/permission_handler.dart'; await Permission.notification.request();
内容的提问来源于stack exchange,提问作者Nitai Dan
相关产品推荐
相关产品推荐

