flutter混合項目在iOS14真機(jī)debug模式啟動閃退

現(xiàn)象:項目中集成了flutter, 使用iOS14系統(tǒng)真機(jī)在斷開調(diào)試后,點擊App圖標(biāo)啟動閃退。

原因:deug模式下,flutter為了實現(xiàn)熱重載,默認(rèn)編譯方式為JIT。而iOS14系統(tǒng)對這種編譯模式做了限制,導(dǎo)致無法啟動。

解決方案:

1.更改XCode編譯模式:使用release模式編譯,這個時候flutter編譯方式為AOT,可正常啟動。

2.不更改XCode編譯模式:更改flutter編譯配置,強(qiáng)制設(shè)置為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獲取編譯模式的函數(shù),如果沒有自主設(shè)置將和Xcode編譯模式保持一致,可以修改local build_mode="release"。強(qiáng)制flutter的編譯模式為release。

新增:flutter版本3.0.0在xcode_backend.drat中修改

————————————————
版權(quán)聲明:本文為CSDN博主「桃花仙丶」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/m0_38126868/article/details/110128841

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容