Flutter-解决混合开发iOS脚本打包遇到的问题

Posted FSA全栈行动

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter-解决混合开发iOS脚本打包遇到的问题相关的知识,希望对你有一定的参考价值。

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

Shell

1
2
3
4
5
6
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

定位错误

Shell

1
2
3
4
5
6
7
8
9
10
11
12
# 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 脚本进行打包,所以方案二不适用,我们选择方案一,且方案一更加方便些

Shell

1
2
3
4
5
# 设置Flutter的编译模式为release
export FLUTTER_BUILD_MODE=release

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


以上是关于Flutter-解决混合开发iOS脚本打包遇到的问题的主要内容,如果未能解决你的问题,请参考以下文章

Flutter混合开发:在已有iOS项目中引入Flutter

Flutter混合开发:在已有iOS项目中引入Flutter

Flutter和iOS混合开发iOS14启动闪退

iOS与Flutter混合开发

flutter 混合开发实现热更新

flutter打包aar并上传Maven私服,flutter模块与原生工程解耦