Mac下, Flutter項(xiàng)目在Xcode 14.3運(yùn)行報(bào)錯(cuò)匯總

開發(fā)環(huán)境

  • macOS Ventura 13.4
  • Xcode 14.3

Xcode 14.3 無法運(yùn)行測(cè)試

   模擬器file not found: libarclite_iphonesimulator.a
   真機(jī)  file not found: libarclite_iphoneos.a

這個(gè)問題分為2方面解決:

  1. Xcode 14.3版本移除了內(nèi)置ARC相關(guān)的庫,從而導(dǎo)致一些默認(rèn)部署目標(biāo)是iOS 8版本的第三方庫出現(xiàn)報(bào)錯(cuò)。只要最低部署目標(biāo)不低于iOS 9版本,運(yùn)行項(xiàng)目時(shí)就不會(huì)去鏈接ARC相關(guān)的庫,也就不會(huì)出現(xiàn)找不到庫的報(bào)錯(cuò)。
    在Podfile文件中添加
post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
        end
    end
end

2.有時(shí)候必須支持老版本, 不管用模擬器還是真機(jī)測(cè)試的時(shí)候, 僅僅是添加上述代碼, 依然無法運(yùn)行. 因此我們需要將未升級(jí)前的arc文件復(fù)制到Xcode 14.3
轉(zhuǎn)至arc下載頁
解壓后復(fù)制到指定的目錄路徑:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib

Xcode 14.3 Command PhaseScriptExecution failed with a nonzero exit code

由于Pods-app-frameworks.sh編譯時(shí), 出現(xiàn)的問題

全局搜索
source="$(readlink "${source}")"
替換為
source="$(readlink -f "${source}")"

但是, 每當(dāng)重新build的時(shí)候, 編譯文件又回歸原始, 因此我們可以在Podfile文件post_install do |installer|中添加

shell_script_path = "Pods/Target Support Files/#{target.name}/#{target.name}-frameworks.sh"
          if File::exists?(shell_script_path)
            shell_script_input_lines = File.readlines(shell_script_path)
            shell_script_output_lines = shell_script_input_lines.map { |line| line.sub("source=\"$(readlink \"${source}\")\"", "source=\"$(readlink -f \"${source}\")\"") }
            File.open(shell_script_path, 'w') do |f|
              shell_script_output_lines.each do |line|
                f.write line
              end
          end
        end

這樣, 就會(huì)在build的時(shí)候, 自動(dòng)替換.

post_install do |installer| 的一些變量

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 11.0
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
      end
      if config.name == 'Test'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)','TEST=1']
        config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = ['$(inherited)','TEST']
        config.build_settings['GCC_OPTIMIZATION_LEVEL'] = 0
        config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
      end
    end
  end
end
IPHONEOS_DEPLOYMENT_TARGET 庫最低版本設(shè)置
GCC_PREPROCESSOR_DEFINITIONS 編譯環(huán)境配置
SWIFT_ACTIVE_COMPILATION_CONDITIONS 編譯環(huán)境配置
GCC_OPTIMIZATION_LEVEL oc編譯優(yōu)化級(jí)別
SWIFT_OPTIMIZATION_LEVEL swift編譯級(jí)別優(yōu)化
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過簡(jiǎn)信或評(píng)論聯(lián)系作者。

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