现象:使用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:]")"
local build_mode="release"
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。
回到工程重新跑模拟器 发现启动失败 只有改回上续改的。。。。
原文链接 https://blog.csdn.net/m0_38126868/article/details/110128841
开始Flutter 学习探讨可以留言和分享