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

React Native+Firebase应用在iOS模拟器无法启动,编译报错求助

问题

我使用Expo裸工作流开发集成Firebase的React Native应用,Android端运行正常,但iOS模拟器启动开发服务器时持续报错。已严格遵循React Native官方文档配置开发环境,也按rnfirebase.io指引完成Firebase全配置,寻求技术解决方案。

报错信息

❌  (ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatStorage.swift:109:38)

  107 |   func readAndWriteAsync(using transform: @escaping (HeartbeatsBundle?) -> HeartbeatsBundle?) {
  108 |     queue.async { [self] in
> 109 |       let oldHeartbeatsBundle = try? load(from: storage)
      |                                      ^ 闭包中调用'load'方法需要显式添加'self.'以明确捕获语义
  110 |       let newHeartbeatsBundle = transform(oldHeartbeatsBundle)
  111 |       try? save(newHeartbeatsBundle, to: storage)
  112 |     }


❌  (ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatStorage.swift:109:49)

  107 |   func readAndWriteAsync(using transform: @escaping (HeartbeatsBundle?) -> HeartbeatsBundle?) {
  108 |     queue.async { [self] in
> 109 |       let oldHeartbeatsBundle = try? load(from: storage)
      |                                                 ^ 闭包中引用'storage'属性需要显式添加'self.'以明确捕获语义
  110 |       let newHeartbeatsBundle = transform(oldHeartbeatsBundle)
  111 |       try? save(newHeartbeatsBundle, to: storage)
  112 |     }


❌  (ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatStorage.swift:111:12)

  109 |       let oldHeartbeatsBundle = try? load(from: storage)
  110 |       let newHeartbeatsBundle = transform(oldHeartbeatsBundle)
> 111 |       try? save(newHeartbeatsBundle, to: storage)
      |            ^ 闭包中调用'save'方法需要显式添加'self.'以明确捕获语义
  112 |     }
  113 |   }
  114 | 


❌  (ios/Pods/FirebaseCoreInternal/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatStorage.swift:111:42)

  109 |       let oldHeartbeatsBundle = try? load(from: storage)
  110 |       let newHeartbeatsBundle = transform(oldHeartbeatsBundle)
> 111 |       try? save(newHeartbeatsBundle, to: storage)
      |                                          ^ 闭包中引用'storage'属性需要显式添加'self.'以明确捕获语义
  112 |     }
  113 |   }
  114 | 

› Compiling @react-native-firebase/auth Pods/FirebaseCoreInternal » RingBuffer.swift
› Compiling @react-native-firebase/auth Pods/FirebaseCoreInternal » _ObjC_HeartbeatController.swift
› Compiling @react-native-firebase/auth Pods/FirebaseCoreInternal » HeartbeatController.swift
› Compiling @react-native-firebase/auth Pods/FirebaseCoreInternal » HeartbeatsBundle.swift
› Compiling @react-native-firebase/auth Pods/FirebaseCoreInternal » Heartbeat.swift
› Compiling react-native Pods/RCT-Folly » SysUio.cpp
› Compiling react-native Pods/RCT-Folly » FileUtil.cpp
› Compiling react-native Pods/RCT-Folly » NetOps.cpp
› Packaging @react-native-firebase/auth Pods/GoogleDataTransport » libGoogleDataTransport.a
› Packaging react-native Pods/RCT-Folly » libRCT-Folly.a
› Compiling @react-native-firebase/auth Pods/FirebaseCoreDiagnostics » FIRCoreDiagnostics.m
    Capabilities for Signing & Capabilities may not function correctly because its entitlements use a placeholder team ID. To resolve this, select a development team in the Gocoinet editor. (in target 'Gocoinet' from project 'Gocoinet')

› 4 error(s), and 1 warning(s)

CommandError: Failed to build iOS project. "xcodebuild" exited with error code 65.

解决方案

这些错误是Swift编译时的捕获语义问题,通常由Xcode版本与Firebase依赖版本不兼容、Swift版本配置缺失导致,按以下步骤解决:

  • 确认Xcode版本:确保使用Xcode 12及以上稳定版,这类版本对Swift闭包的self捕获有明确要求,旧版本可能不兼容最新Firebase Pods。
  • 更新Firebase依赖:
    在项目根目录执行:
    npm install @react-native-firebase/app@latest @react-native-firebase/auth@latest
    
    进入iOS目录更新Pods:
    cd ios
    pod update FirebaseCoreInternal FirebaseCore
    
  • 指定Swift版本:
    编辑ios/Podfile,在post_install块中添加Swift版本配置(确保版本为5.3+):
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '5.3'
        end
      end
    end
    
  • 清理缓存并重新构建:
    # 删除Pods目录和锁定文件
    rm -rf ios/Pods
    rm ios/Podfile.lock
    # 清理Xbuild缓存
    xcodebuild clean
    # 重新安装Pods
    cd ios && pod install
    
  • 处理签名警告:
    打开Xcode中的ios/Gocoinet.xcworkspace,选择Gocoinet目标,进入Signing & Capabilities面板,选择你的Apple开发团队,替换占位符Team ID。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 12:10:22