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

React Native iOS构建失败求助:多类错误及已尝试方案

React Native iOS构建问题解决方案(Mac M2)

针对CocoaPods版本兼容错误

操作步骤:

  • 打开ios/Podfile,将platform :ios, 'x.x'修改为与你的React Native版本匹配的最低部署目标:
    • RN 0.70.x~0.73.x:设置为'13.0'
    • RN 0.74.x及以上:设置为'14.0'
  • 同步Xcode项目部署目标:打开Xcode,进入项目TARGETS → 项目名称 → General → Deployment Info,将iOS Deployment Target设为与Podfile一致的版本
  • 彻底清理并重装Pods:
    cd ios
    rm -rf Pods Podfile.lock
    pod deintegrate
    pod setup
    pod install --repo-update
    

针对PhaseScriptExecution失败错误

操作步骤:

  • 配置Xcode的node路径:
    打开Xcode → 项目TARGETS → 项目名称 → Build Phases → [CP-User] Generate app.config for prebuilt Constants.ios.js,在脚本开头添加:
    export NODE_BINARY=$(which node)
    
  • 添加M2架构适配配置到Podfile:
    在post_install块中补充架构排除配置:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0' # 与你的部署版本保持一致
          config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
        end
      end
      react_native_post_install(installer)
    end
    
  • 修复脚本执行权限:
    chmod +x node_modules/react-native/scripts/*.sh
    

针对模拟器运行配置文件读取失败错误

操作步骤:

  • 确认iPhone 15模拟器已安装:打开Xcode → Window → Devices and Simulators,检查iPhone 15模拟器是否存在,缺失则点击"+"添加
  • 用Rosetta运行终端:右键终端 → 显示简介 → 勾选"使用Rosetta打开",再执行:
    npx react-native run-ios --no-packager --simulator="iPhone 15"
    
  • 检查Xcode签名配置:进入TARGETS → 项目名称 → Signing & Capabilities,勾选"Automatically manage signing"并选择正确的开发团队

内容的提问来源于stack exchange,提问作者노원재

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 12:27:18