Flutter iOS模拟器编译报错:找不到FlutterLocalNotificationsPlugin
解决iOS模拟器中Flutter项目编译错误:Cannot find 'FlutterLocalNotificationsPlugin' in scope
问题描述
在iOS(iPhone)模拟器运行Flutter项目时,出现以下编译错误:
Xcode build done. 12.7s Failed to build iOS app Swift Compiler Error (Xcode): Cannot find 'FlutterLocalNotificationsPlugin' in scope /Users/mojamal/Desktop/nesp_application/ios/Runner/AppDelegate.swift:14:42 Could not build the application for the simulator. Error launching application on iPhone 15 Pro Max.
已尝试以下操作但未解决:
- 回退至历史提交记录排查
- 执行
flutter pub upgrade→flutter pub get→flutter clean→flutter build ios→cd ios→pod install命令序列
同时收到代码签名证书提示,该提示与当前编译错误无关,可忽略。
解决方案
1. 检查AppDelegate.swift的导入语句
打开ios/Runner/AppDelegate.swift,确保文件顶部添加了插件的导入:
import FlutterLocalNotificationsPlugin
2. 验证依赖配置
- 确认
pubspec.yaml中已正确声明flutter_local_notifications依赖,版本适配当前Flutter版本 - 执行
flutter pub get后,检查ios/Podfile.lock文件中是否存在FlutterLocalNotificationsPlugin的相关记录
3. 重新生成插件注册文件
删除ios/Runner/GeneratedPluginRegistrant.swift,然后执行:
flutter clean flutter pub get
Flutter会自动重新生成插件注册文件,确保插件被正确注册。
4. 彻底重置Pod依赖
执行以下命令清理并重新安装Pod:
cd ios pod deintegrate pod install
5. Xcode清理构建
打开ios/Runner.xcworkspace,执行:
Product > Clean Build Folder
然后重新构建项目。
内容的提问来源于stack exchange,提问作者Mohammed Jamal
相关产品推荐
相关产品推荐

