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

升级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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 13:15:51