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

M2芯片Sonoma系统RN 0.73.4 iOS构建报错:Command PhaseScriptExecution失败

React Native 0.73.4 iOS构建失败:Command PhaseScriptExecution failed with a nonzero exit code

环境信息

System:
  OS: macOS 14.3
  CPU: (12) arm64 Apple M2 Pro
  Memory: 87.56 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.6.1
    path: ~/.nvm/versions/node/v21.6.1/bin/node
  Yarn:
    version: 1.22.21
    path: ~/.nvm/versions/node/v21.6.1/bin/yarn
  npm:
    version: 10.2.4
    path: ~/.nvm/versions/node/v21.6.1/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 34.0.0
    System Images:
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-UpsideDownCakePrivacySandbox | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 3.3.0
    path: /Users/muhammadhuzaifajunaid/.rubies/ruby-3.3.0/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.4
    wanted: 0.73.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true

问题概述

在M2 Pro芯片的macOS Sonoma 14.3上,使用Xcode 15.2搭建React Native 0.73.4 iOS环境,手动完成依赖安装(sudo npm install、sudo bundle install、sudo bundle exec pod install --allow-root)后,Xcode构建时出现Command PhaseScriptExecution failed with a nonzero exit code报错,已尝试Homebrew/Gems安装CocoaPods、安装ffi,问题仍未解决。

解决方案

1. 修复权限问题(sudo执行导致的权限混乱)

  • 重置项目及相关依赖目录的权限,避免root权限冲突:
    sudo chown -R $(whoami) ~/.npm ~/.nvm ./node_modules ./ios/Pods
    
  • 放弃使用sudo执行npm、bundle、pod命令,用当前用户重新执行依赖安装:
    npm install
    cd ios
    bundle install
    bundle exec pod install
    

2. 调整Xcode脚本配置(适配Xcode 15兼容性)

  • 打开Xcode,进入项目的Build Phases:
    • 找到Bundle React Native code and images或[CP-User] Generate Specs脚本,将脚本的Shell路径从默认的/bin/sh改为/bin/bash或/opt/homebrew/bin/zsh(适配M芯片的Homebrew环境)。
    • 如果报错与Hermes相关,在Build Settings中搜索HERMES_CLI_PATH,确保路径指向$(SRCROOT)/../node_modules/hermes-engine/osx-bin/hermes。

3. 清理缓存并重新构建

  • 清理React Native缓存:
    npx react-native clean
    
  • 清理Xcode及CocoaPods缓存:
    # 关闭Xcode后执行
    rm -rf ~/Library/Developer/Xcode/DerivedData
    cd ios
    pod deintegrate
    pod clean
    pod install
    
  • 重新打开Xcode,按下Cmd+Shift+K清理Build Folder,再尝试构建。

4. 调整Ruby版本(适配CocoaPods兼容性)

CocoaPods 1.15.2与Ruby 3.3.0存在兼容问题,建议切换到Ruby 3.2.x版本:

  • 使用rbenv/rvm切换Ruby版本(以rbenv为例):
    rbenv install 3.2.3
    rbenv local 3.2.3
    
  • 重新安装CocoaPods到当前Ruby环境:
    gem install cocoapods
    # 检查pod路径是否指向当前Ruby的bin目录
    which pod
    
  • 回到ios目录重新执行bundle install && bundle exec pod install。

5. 检查Xcode构建配置

  • 在Xcode的Build Settings中,确保iOS Deployment Target设置为13.0或更高(React Native 0.73.4要求最低iOS 13.0)。
  • 将Build Active Architecture Only在Debug模式下设置为Yes,Release模式下设置为No。
  • 打开Xcode的Settings -> Components,确认已安装iOS 17.2模拟器及对应的SDK组件。

内容的提问来源于stack exchange,提问作者Huzaifa Junaid

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 07:43:23