React Native iOS模拟器运行报错(RNFBMessaging目标)
iOS模拟器编译RNFBMessaging失败的解决办法
问题背景
Android应用开发及发布流程正常,已完成应用发布,但在iOS模拟器中运行应用时出现编译错误,具体报错如下:
错误信息
The following build commands failed: CompileC /Users/sirket/Library/Developer/Xcode/DerivedData/cmsio-doadelmxvtbipqeduigsnvnzbamx/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/RNFBMessaging.build/Objects-normal/x86_64/RNFBMessagingSerializer.o /Users/sirket/Desktop/android/cmsio/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessagingSerializer.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'RNFBMessaging' from project 'Pods') (1 failure)
当前使用的Podfile配置:
require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '13.0' install! 'cocoapods', :deterministic_uuids => false production = ENV["PRODUCTION"] == "1" target 'cmsio' do config = use_native_modules! # Flags change depending on the env values. flags = get_default_flags() use_react_native!( :path => config[:reactNativePath], # to enable hermes on iOS, change `false` to `true` and then install pods :production => production, :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], :flipper_configuration => FlipperConfiguration.enabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) permissions_path = '../node_modules/react-native-permissions/ios' pod 'RNFBMessaging', :path => '../node_modules/@react-native-firebase/messaging' pod 'react-native-google-maps', :path => '../node_modules/react-native-maps' pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary" pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy" pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways" pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse" pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications" pod 'Firebase', :modular_headers => true pod 'FirebaseCore', :modular_headers => true pod 'Firebase/Messaging', :modular_headers => true pod 'FirebaseCoreInternal', :modular_headers => true pod 'GoogleUtilities', :modular_headers => true pod 'Google-Mobile-Ads-SDK' $RNFirebaseAsStaticFramework = true $RNGoogleMobileAdsAsStaticFramework = true target 'cmsioTests' do inherit! :complete # Pods for testing end post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end
解决方案
1. 清理缓存并重新安装依赖
- 进入iOS目录,删除Pods文件夹和Podfile.lock:
cd ios rm -rf Pods Podfile.lock - 删除Xcode衍生数据,避免旧缓存干扰:
rm -rf ~/Library/Developer/Xcode/DerivedData/cmsio-doadelmxvtbipqeduigsnvnzbamx - 更新pod仓库并重新安装:
pod install --repo-update
2. 调整Podfile配置
- 将静态框架声明移到Podfile最顶部,确保在引入依赖前生效:
修改后的Podfile开头:require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' $RNFirebaseAsStaticFramework = true $RNGoogleMobileAdsAsStaticFramework = true platform :ios, '13.0' install! 'cocoapods', :deterministic_uuids => false - 移除重复的Firebase/Messaging依赖,因为
RNFBMessaging已经包含该模块:
删除这一行:pod 'Firebase/Messaging', :modular_headers => true
3. 调整Xcode编译设置
- 打开
ios/cmsio.xcworkspace,在Pods项目中找到RNFBMessagingtarget:- 进入
Build Settings,找到Apple Clang - Language - Modules,设置Enable Modules (C and Objective-C)为YES - 找到
Build Options,将Validate Workspace设为YES,然后重新编译
- 进入
- 检查主项目架构设置:
选中cmsio主target,进入Build Settings->Architectures:- 设置
Architectures为Standard Architectures (arm64, x86_64) - 在
Excluded Architectures的Debug-iphonesimulator配置中添加arm64
- 设置
4. 升级依赖版本
- 更新
@react-native-firebase/messaging到最新兼容版本:npm install @react-native-firebase/messaging@latest - 同时确保
react-native和其他Firebase相关依赖版本匹配,避免版本冲突
内容的提问来源于stack exchange,提问作者Savaş Dersim Çelik
相关产品推荐
相关产品推荐

