升级Firebase至最新版本后Flutter iOS应用无法运行
iOS Flutter App Crash After Upgrading Firebase Dependencies: "Object for handle already exists: 1"
问题场景
升级Firebase依赖至以下版本后,iOS应用编译成功但启动崩溃,抛出异常:
libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object for handle already exists: 1' terminating with uncaught exception of type NSException
使用的Firebase依赖版本:
firebase_core: 2.4.0 firebase_crashlytics: 3.0.8 firebase_analytics: 10.0.8 firebase_performance: 0.9.0+8 firebase_remote_config: 3.0.8
注:Android版本编译运行正常。
解决方案
1. 清理iOS构建缓存并重新集成Pods
- 执行
flutter clean清理Flutter项目缓存 - 删除iOS目录下的
Podfile.lock文件 - 进入iOS目录,执行
pod deintegrate完全移除现有Pods - 执行
pod install --repo-update更新Pod仓库并重新安装依赖 - 重启Xcode,按下
Cmd+Shift+K清理Xcode构建缓存,再重新运行应用
2. 确保Firebase仅初始化一次
检查Flutter代码,确认Firebase.initializeApp()只被调用一次,建议放在main函数的最开始位置:
void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(const MyApp()); }
避免在多个页面或组件中重复调用初始化方法。
3. 检查iOS端Firebase配置完整性
- 确认
GoogleService-Info.plist是从Firebase控制台下载的最新版本,且在Xcode中仅添加了一次 - 检查Xcode项目的
Build Phases,确保没有重复添加Firebase相关的运行脚本(比如Crashlytics的上传脚本)
4. 降级存在兼容性问题的依赖(备选)
如果上述方法无效,尝试暂时降级firebase_performance版本,比如修改为:
firebase_performance: 0.8.0+7
之后重新执行pod install,再测试应用启动情况。
内容的提问来源于stack exchange,提问作者Carlos Daniel
相关产品推荐
相关产品推荐

