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

使用Fastlane部署React Native应用到Firebase Distribution时出现PhaseScriptExecution错误

React Native + Fastlane + Github Actions 部署到Firebase Distribution构建失败问题

我在使用Fastlane将React Native应用部署到Firebase Distribution时遇到报错,本地构建完全正常,仅在Github Actions CI环境下触发该问题:

[33m▸[0m [39;1mRunning script[0m 'Bundle React Native code and images'
2021-09-14T23:45:37.0115340Z     [33mthe transform cache was reset.[0m
2021-09-14T23:45:37.0116230Z ** ARCHIVE FAILED **
2021-09-14T23:45:37.0116680Z 
2021-09-14T23:45:37.0117040Z 
2021-09-14T23:45:37.0117840Z The following build commands failed:
2021-09-14T23:45:37.0121970Z    PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/runner/Library/Developer/Xcode/DerivedData/proj_name-ghtelxhdqifreogqusciceodxxjy/Build/Intermediates.noindex/ArchiveIntermediates/proj_name.firebasedistribution/IntermediateBuildFilesPath/proj_name.build/FirebaseDistribution-iphoneos/mobile.build/Script-00DD1BFF1BD5951E006B06BC.sh
2021-09-14T23:45:37.0125070Z (1 failure)
2021-09-14T23:45:37.0126250Z [23:45:24]: [31mExit status: 65[0m
2021-09-14T23:45:37.0126990Z [23:45:24]: 
2021-09-14T23:45:37.0128480Z [23:45:24]: [33mMaybe the error shown is caused by using the wrong version of Xcode[0m
2021-09-14T23:45:37.0130200Z [23:45:24]: [33mFound multiple versions of Xcode in '/Applications/'[0m
2021-09-14T23:45:37.0131900Z [23:45:24]: [33mMake sure you selected the right version for your project[0m
2021-09-14T23:45:37.0134030Z [23:45:24]: [33mThis build process was executed using '/Applications/Xcode_12.4.app'[0m
2021-09-14T23:45:37.0135690Z [23:45:24]: [33mIf you want to update your Xcode path, either[0m
2021-09-14T23:45:37.0136580Z [23:45:24]: 
2021-09-14T23:45:37.0137960Z [23:45:24]: - Specify the Xcode version in your Fastfile
2021-09-14T23:45:37.0139560Z [23:45:24]: ▸ [35mxcversion(version: "8.1") # Selects Xcode 8.1.0[0m
2021-09-14T23:45:37.0140440Z [23:45:24]: 
2021-09-14T23:45:37.0141920Z [23:45:24]: - Specify an absolute path to your Xcode installation in your Fastfile
2021-09-14T23:45:37.0143580Z [23:45:24]: ▸ [35mxcode_select "/Applications/Xcode8.app"[0m
2021-09-14T23:45:37.0144470Z [23:45:24]: 
2021-09-14T23:45:37.0145670Z [23:45:24]: - Manually update the path using
2021-09-14T23:45:37.0147210Z [23:45:24]: ▸ [35msudo xcode-select -s /Applications/Xcode.app[0m
2021-09-14T23:45:37.0148140Z [23:45:24]: 
2021-09-14T23:45:37.0148540Z 
2021-09-14T23:45:37.0149750Z +---------------+------------------------------+
2021-09-14T23:45:37.0151420Z |              [32m[33mBuild environment[0m               |
2021-09-14T23:45:37.0152920Z +---------------+------------------------------+
2021-09-14T23:45:37.0153960Z | xcode_path    | /Applications/Xcode_12.4.app |
2021-09-14T23:45:37.0154900Z | gym_version   | 2.192.0                      |
2021-09-14T23:45:37.0156180Z | export_method | ad-hoc                       |
2021-09-14T23:45:37.0157130Z | sdk           | iPhoneOS14.4.sdk             |
2021-09-14T23:45:37.0158480Z +---------------+------------------------------+
2021-09-14T23:45:37.0159020Z 
2021-09-14T23:45:37.0160290Z [23:45:25]: ▸ [35m    at Generator.next (<anonymous>)[0m
2021-09-14T23:45:37.0162550Z [23:45:25]: ▸ [35m    at asyncGeneratorStep (/Users/runner/work/proj_name/proj_name/node_modules/metro/src/DeltaBundler/traverseDependencies.js:137:24)[0m
2021-09-14T23:45:37.0165140Z [23:45:25]: ▸ [35m    at _next (/Users/runner/work/proj_name/proj_name/node_modules/metro/src/DeltaBundler/traverseDependencies.js:159:9)[0m
2021-09-14T23:45:37.0167140Z [23:45:25]: ▸ [35minfo Run CLI with --verbose flag for more details.[0m
2021-09-14T23:45:37.0168770Z [23:45:25]: ▸ [35mCommand /bin/sh failed with exit code 1[0m

环境配置

  • node版本:14.17.3
  • Xcode版本:12.4
  • 运行环境:Github Actions CI

我已将Bundle React Native code and images的执行路径设置为:../node_modules/react-native/scripts/react-native-xcode.sh,但问题没有得到解决。

已尝试的解决方案

  • 参考相关方案,在node_modules/..前添加node前缀:
export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh"
  • 将Build React native code and Images中的export NODE_BINARY=node修改为export NODE_BINARY=$(which node)
  • 尝试在Build React native code and images脚本顶部添加cd $PROJECT_DIR/..:
cd $PROJECT_DIR/..
export DEVELOPMENT_BUILD_CONFIGURATIONS="+(LocalDevelopment|FirebaseDistribution|Debug)"
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh

以上方案均未解决问题。

可行解决方案

方案1:在Github Actions workflow中明确传递Node路径

CI环境下Xcode默认无法读取nvm等工具安装的Node路径,需要在workflow的构建步骤前显式将Node路径写入全局环境变量:
在Fastlane执行步骤前添加以下配置:

- name: 导出Node路径到环境变量
  run: |
    echo "NODE_BINARY=$(which node)" >> $GITHUB_ENV

同时修改Xcode中的Bundle React Native code and images脚本为:

export NODE_BINARY=${NODE_BINARY:-node}
cd $PROJECT_DIR/..
./node_modules/react-native/scripts/react-native-xcode.sh

方案2:禁用metro缓存避免CI兼容性问题

在调用打包脚本前添加缓存重置配置,修改Bundle React Native code and images脚本:

export BUNDLE_COMMAND="bundle --reset-cache"

方案3:Fastfile中显式传递环境变量

在Fastfile的gym调用配置中添加Node路径传递:

gym(
  # 原有其他gym配置不变
  export_method: "ad-hoc",
  environment_variables: {
    "NODE_BINARY" => `which node`.strip
  }
)

方案4:修复CI依赖安装完整性

CI环境可能存在依赖安装不全的问题,调整依赖安装步骤:

- name: 安装依赖
  run: |
    rm -rf node_modules
    yarn install --frozen-lockfile

内容的提问来源于stack exchange,提问作者Divyesh Puri

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 03:57:02