React Native iOS构建失败:Xcode错误码65与AppDelegate.m选择器错误
解决React Native 0.68+在Xcode 15+上的构建错误
问题1:RCT-Folly模块编译失败(xcodebuild错误码65)
原因
Xcode 15对C++编译标准和符号处理逻辑做了调整,旧版本RCT-Folly依赖的编译配置不兼容新环境。
修复步骤
- 修改
ios/Podfile,添加RCT-Folly的适配配置:
在target 'MYVU' do代码块末尾插入以下内容:post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "RCT-Folly" target.build_configurations.each do |config| # 添加兼容Xcode 15的编译参数 config.build_settings['CXXFLAGS'] = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' config.build_settings['CCFLAGS'] = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' end end end end - 清理Pod缓存并重新安装依赖:
rm -rf ios/Pods ios/Podfile.lock npx pod-install ios - 清理Xcode构建缓存:
xcodebuild clean -workspace MYVU.xcworkspace -scheme MYVU -configuration Debug
问题2:AppDelegate.m中RCTBundleURLProvider selector错误
原因
React Native 0.68+版本废弃了jsBundleURLForBundleRoot:fallbackResource:方法,Xcode 15严格的语法检查会触发该错误。
修复步骤
打开ios/MYVU/AppDelegate.m,替换原有的JS bundle路径获取代码:
原错误代码:
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
替换为兼容代码:
NSURL *jsCodeLocation; #ifdef DEBUG // Debug环境使用本地打包服务地址 jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else // Release环境使用本地打包好的jsbundle文件 jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif
额外优化建议
- Node版本适配:React Native 0.68推荐使用Node.js 14-18 LTS版本,当前使用的Node v21存在兼容性风险,建议通过nvm切换到Node 18:
nvm install 18 nvm use 18 - 若上述修复仍无效,考虑升级React Native到0.72+版本(该版本原生支持Xcode 15)。
内容的提问来源于stack exchange,提问作者Diego Bolanos
相关产品推荐
相关产品推荐

