升级Mac OS 15.2与Xcode 16.2后React Native项目无法构建求助
Xcode 16.2 构建 React Native 0.72.17 项目失败求助
环境信息
- React Native 版本:0.72.17
- 设备:M3 MacBook
- Xcode 版本:16.2(此前搭配旧系统+Xcode15可正常运行)
- CocoaPods 版本:1.14.3(已尝试升级至1.16.x,无效)
问题描述
升级到Xcode16.2后,项目无法完成构建,未出现明确的依赖相关错误,当前卡在无意义错误(见附图)。已在Podfile中禁用Flipper,Podfile内容如下:
# Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( "react-native/scripts/react_native_pods.rb", {paths: [process.argv[1]]}, )', __dir__]).strip platform :ios, '13.4' # platform :ios, min_ios_version_supported prepare_react_native_project! use_modular_headers! # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded # # To fix this you can also exclude `react-native-flipper` using a `react-native.config.js` # ```js # module.exports = { # dependencies: { # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), # ``` # flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled linkage = ENV['USE_FRAMEWORKS'] if linkage != nil Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! :linkage => linkage.to_sym end target 'buds' do config = use_native_modules! # Flags change depending on the env values. flags = get_default_flags() use_frameworks! :linkage => :static $RNFirebaseAsStaticFramework = true use_react_native!( :path => config[:reactNativePath], # Hermes is now enabled by default. Disable by setting this flag to false. :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable the next line. # :flipper_configuration => flipper_config, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) target 'budsTests' do inherit! :complete # Pods for testing end post_install do |installer| # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false ) # __apply_Xcode_12_5_M1_post_install_workaround(installer) end end
解决建议
- 添加Xcode16兼容性补丁:RN 0.72版本未官方适配Xcode16,可在
post_install中补充以下代码,修复Swift版本和架构兼容问题:installer.pods_project.targets.each do |target| target.build_configurations.each do |config| # 强制Swift版本为5.0(适配旧依赖) config.build_settings['SWIFT_VERSION'] = '5.0' # 修复M3架构相关问题 config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = '' end end - 彻底清理构建缓存:
- 执行
rm -rf node_modules && npm install - 进入ios目录:
cd ios && pod deintegrate && pod install --repo-update - Xcode中按
Cmd+Shift+K清理构建,再手动删除Derived Data(路径:Xcode → 设置 → 位置 → Derived Data)
- 执行
- 调整Podfile配置:
- 将
platform :ios版本改为'14.0',Xcode16对iOS13.x的兼容支持有限 - 暂时注释
use_frameworks! :linkage => :static,测试是否为静态框架导致的冲突,若正常再逐个排查依赖的框架设置
- 将
- 检查Xcode构建设置:
- 项目Target的Build Settings中,将
Build Libraries for Distribution设为NO - 确保
Valid Architectures包含arm64,Architectures设置为Standard Architectures
- 项目Target的Build Settings中,将
- 排查完整日志:Xcode中点击构建失败提示,展开全部日志,查找被隐藏的具体错误(如某个第三方依赖的编译报错)
内容的提问来源于stack exchange,提问作者hugger
相关产品推荐
相关产品推荐

