现象:项目中集成了flutter, 使用iOS14系统真机在断开调试后,点击App图标启动闪退。
原因:deug模式下,flutter为了实现热重载,默认编译方式为JIT。而iOS14系统对这种编译模式做了限制,导致无法启动。
解决方案:
1.更改XCode编译模式:使用release模式编译,这个时候flutter编译方式为AOT,可正常启动。
2.不更改XCode编译模式:更改flutter编译配置,强制设置为release。找到flutter安装位置,依次打开flutter/packages/flutter_tools/bin/xcode_backend.sh
ParseFlutterBuildMode() {
# Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
# This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
# they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
local build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")"
case "$build_mode" in
*release*) build_mode="release";;
*profile*) build_mode="profile";;
*debug*) build_mode="debug";;
*)
EchoError "========================================================================"
EchoError "ERROR: Unknown FLUTTER_BUILD_MODE: ${build_mode}."
EchoError "Valid values are 'Debug', 'Profile', or 'Release' (case insensitive)."
EchoError "This is controlled by the FLUTTER_BUILD_MODE environment variable."
EchoError "If that is not set, the CONFIGURATION environment variable is used."
EchoError ""
EchoError "You can fix this by either adding an appropriately named build"
EchoError "configuration, or adding an appropriate value for FLUTTER_BUILD_MODE to the"
EchoError ".xcconfig file for the current build configuration (${CONFIGURATION})."
EchoError "========================================================================"
exit -1;;
esac
echo "${build_mode}"
}
ParseFlutterBuildMode是flutter获取编译模式的函数,如果没有自主设置将和Xcode编译模式保持一致,可以修改local build_mode="release"。强制flutter的编译模式为release。
新增:flutter版本3.0.0在xcode_backend.drat中修改
————————————————
版权声明:本文为CSDN博主「桃花仙丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_38126868/article/details/110128841