升级React Native Firebase后iOS构建Linker命令失败求助
React Native Firebase v10升级到v17后iOS构建链接错误解决方案
问题描述
将React Native Firebase从v10升级到v17后,iOS版本构建失败,Android构建正常。核心错误为链接器命令失败,同时伴随多个Pod部署目标版本过低的警告。
错误信息
ld: warning: ignoring duplicate libraries: '-lc++' ld: building for 'iOS-simulator', but linking in object file (/.../ios/Pods/Crashlytics/iOS/Crashlytics.framework/Crashlytics[arm64][2](CLSBinaryImage.o)) built for 'iOS' clang: error: linker command failed with exit code 1 (use -v to see invocation) /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'React-RCTActionSheet' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'Fabric' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'React-callinvoker' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 11.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'Firebase' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'boost-for-react-native' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'RCTRequired' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'FBLazyVector' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'React' from project 'Pods') /.../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 12.0 to 17.2.99. (in target 'Crashlytics' from project 'Pods') --- xcodebuild: WARNING: Using the first of multiple matching destinations: { platform:iOS Simulator, id:637201FD-B9E2-4C2E-8797-6DD23CC5440C, OS:17.0, name:iPhone 11 } { platform:iOS Simulator, id:637201FD-B9E2-4C2E-8797-6DD23CC5440C, OS:17.0, name:iPhone 11 } ** BUILD FAILED ** The following build commands failed: Ld /.../Library/Developer/Xcode/DerivedData/backporch-gklonbvhvuffcrcrsbundznbgjak/Build/Products/Debug-iphonesimulator/Backporch.app/Backporch normal (in target 'backporch' from project 'backporch') (1 failure)
当前Podfile内容
use_frameworks! :linkage => :static require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' require_relative '../node_modules/react-native/scripts/react_native_pods' # use_modular_headers! platform :ios, '11.0' target 'backporch' do config = use_native_modules! use_react_native!(:path => config["reactNativePath"]) target 'backporchTests' do inherit! :complete # Pods for testing end # Enables Flipper. post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings["ONLY_ACTIVE_ARCH"] = "YES" end end installer.pods_project.targets.each do |target| if (target.name&.eql?('FBReactNativeSpec')) target.build_phases.each do |build_phase| if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs')) target.build_phases.move(build_phase, 0) end end end end end # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable these next few lines. # use_flipper!({ 'Flipper-Folly' => '2.3.0' }) # post_install do |installer| # flipper_post_install(installer) # end end
环境版本
- React Native 0.63.5
- React Native Firebase 17.5.0
- Xcode 15
解决方案
1. 统一所有Pod的部署目标版本
Xcode 15要求最低部署目标为iOS 12.0,当前多个Pod的IPHONEOS_DEPLOYMENT_TARGET低于该值,需在Podfile的post_install钩子中统一设置:
修改后的post_install代码如下:
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| # 统一设置最低iOS部署版本为12.0,匹配Xcode 15支持范围 config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' config.build_settings["ONLY_ACTIVE_ARCH"] = "YES" end end # 保留原有的FBReactNativeSpec构建阶段调整逻辑 installer.pods_project.targets.each do |target| if (target.name&.eql?('FBReactNativeSpec')) target.build_phases.each do |build_phase| if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs')) target.build_phases.move(build_phase, 0) end end end end end
2. 修复Crashlytics架构不兼容问题
错误提示Crashlytics的arm64对象文件为真机编译版本,无法适配模拟器,执行以下步骤:
- 清理现有Pod依赖:
cd ios rm -rf Pods Podfile.lock pod deintegrate
- 重新安装Pod:
pod install
- 若问题仍存在,在
post_install钩子中添加Crashlytics的架构兼容配置:
在target.build_configurations.each do |config|块内添加:
if target.name == 'Crashlytics' || target.name == 'Fabric' config.build_settings['VALID_ARCHS[sdk=iphonesimulator*]'] = 'x86_64 arm64' end
3. 移除重复的-lc++库引用
针对重复库警告,在Xcode中操作:
- 打开
ios/backporch.xcworkspace - 选择主target
backporch - 进入
Build Settings->Other Linker Flags - 查找并移除重复的
-lc++条目
4. 验证RN Firebase升级配置完整性
- 确保已更新
GoogleService-Info.plist文件到最新版本 - 检查
AppDelegate.m/AppDelegate.swift中的初始化代码,替换为RN Firebase v17的初始化方式(移除旧的Fabric相关代码)
内容的提问来源于stack exchange,提问作者Martin Villegas
相关产品推荐
相关产品推荐

