使用Xcode手动打包是正常的,但是使用脚本打包会报错,错误如下:

The following build commands failed:
    PhaseScriptExecution [CP-User]\ Run\ Flutter\ Build\ Script .../Script-C3A097A8FE12FF5F875B057C.sh

flutter build ios --release
then re-run Archive from Xcode.
Command PhaseScriptExecution failed with a nonzero exit code

定位错误


到Flutter环境目录下,按图上显示地址找到xcode_backend.sh

  # Archive builds (ACTION=install) should always run in release mode.
  if [[ "$ACTION" == "install" && "$build_mode" != "release" ]]; then
    EchoError "========================================================================"
    EchoError "ERROR: Flutter archive builds must be run in Release mode."
    EchoError ""
    EchoError "To correct, ensure FLUTTER_BUILD_MODE is set to release or run:"
    EchoError "flutter build ios --release"
    EchoError ""
    EchoError "then re-run Archive from Xcode."
    EchoError "========================================================================"
    exit -1
  fi

解决方案

可以看到,官方脚本的说明里面称为两个解决方案

方案一:直接设置FLUTTER_BUILD_MODE为release
请在这里输入引用内容
方案二:先运行flutter build ios --release,再使用Xcode去打包

这里我们是用Jenkins脚本进行打包,所以方案二不适用,方案一更加方便些

# 设置Flutter的编译模式为release
export FLUTTER_BUILD_MODE=release

# 执行原有项目的打包脚本
./script/build_iOS.sh