簡介
本來好好的,突然打包不行了,模擬器也不能用了,郁悶了好幾天。后來才發(fā)現(xiàn)原來的是XCode14.3的問題,降級到XCode14.2,就正常了。
打包問題

這里有用的信息不多,根據(jù)Command PhaseScriptExecution failed with a nonzero exit code去百度,得到的方案基本不靠譜
-
去掉CocoaPods腳本執(zhí)行,本地用沒問題,但是提交蘋果市場后就會有問題。
企業(yè)微信截圖_36ef3464-18b6-415d-b909-f258121bdf20.png

- 下面這2個鏈接是正確的原因,XCode14.3改變了路徑的計算方式,CocoaPods腳本需要添加-f參數(shù)才行。
Upgrade from Xcode 14.2 to 14.3 rsync: link_stat failed: No such file or directory (2) for pods that were working earlier.
Xcode 14.3 fix: Pass the -f option when resolving the path to the symlinked source.
Xcode 14.3 is now using a relative path in its symlink for frameworks. Without the -f flag, this relative path would be evaluated relative to the working directory of the script being executed, instead of relative to the framework symlink itself. With the -f flag, it resolves that relative path and returns the full path to the source.
- 提問的時候,CocoaPods的版本是1.11.3,我的MAC上已經(jīng)升級到1.12.0,仍然無效。
如何解決?
把Pods -> Targets Support Files -> Pods-工程名字-frameworks.sh這個配置文件的44行,加個-f參數(shù)就好了

模擬器問題
編譯都不過,第三方庫直接就報錯:
In /Users/zxs/git/ios/storage/Pods/YYImage/Vendor/WebP.framework/WebP(anim_decode.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/zxs/git/ios/storage/Pods/YYImage/Vendor/WebP.framework/WebP' for architecture arm64
解決方法
就是模擬器的時候,需要排除arm64芯片,需要在PodFile中添加以下內(nèi)容:
# Fixed iOS simulator Link error for arm64 architecture on xCode 12.* for Apple M1 chip?
# alse added on **** -> Build Settings -> Excluded architectures -> DebugStaging
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
自動添加-f參數(shù)的腳本
手動加個-f很簡單,但是每次podinstall之后就會被改回去。這里有篇文章介紹在PodFile中用腳本自動改,可以試試。Podfile Xcode 13 readlink fix
post_install do |installer|
project_path = "工程名字.xcodeproj"
project = Xcodeproj::Project.open(project_path)
project.targets.each do |target|
shell_script_path = "Pods/Target Support Files/Pods-工程名字/Pods-"+target.name+"-frameworks.sh"
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
end
降低版本
XCode14.3問題很多,XCode14.2表現(xiàn)穩(wěn)定,所以可以下載一個XCode14.2備用。
- 下載一個XCode14.2,解壓之后改名為XCode_14.2,訪問應(yīng)用程序文件夾,和最新的XCode(14.3)共存。

- 要解決打包的問題,需要進入Xcode_14.2才能解決。
關(guān)于Command Line Tools
網(wǎng)上有文章說,在XCode14.3的環(huán)境中,使用14.2的Command Line Tools來解決問題。

- 經(jīng)過試驗,打包問題無法解決;但是Flutter工程模擬器無法運行的問題可以解決。
大概的原因是Flutter是以命令行的方式調(diào)用XCode編譯的。

這個問題可以通過設(shè)置XCode14.2命令行工具解決
小結(jié)
經(jīng)過多方權(quán)衡,還是將XCode降級為14.2來解決問題比較好。
公司其他同事還沒有升級,就別升級了,繼續(xù)使用XCode14.2
參考文檔
后記
一開始,下載 XCode14.2,保持2個版本共存;
后來,感覺這個XCode14.3實在太差了,莫名其妙的問題太多,果斷刪除;
蘋果這些年是一年比一年差,XCode的問題一年比一年多,喬布斯才是蘋果的靈魂;
正式退回到XCode14.2,并且只保留這一個,刪除惡心的XCode14.3;
后續(xù)版本,要先看網(wǎng)絡(luò)上的評價,才考慮是否升級。
