Xcode12 上使用模擬器編譯項(xiàng)目時(shí)爆阶,出現(xiàn)錯(cuò)誤斥扛。同樣的代碼在Xcode11則不會(huì)有問題。
一些錯(cuò)誤如下:
No such modules (import installed pods)
Cocoapods post-build step with the script they install issue -> Pods/Target Support Files/Pods-All-Apps-XXX/Pods-All-Apps-XXX-frameworks.sh: line 141: ARCHS[@]: unbound variable
‘ObjCheaderFile.h’ file not found. (ObjC Headers in bridging file)
為什么會(huì)出現(xiàn)這些錯(cuò)誤食茎?
在查閱Xcode12的升級文檔蒂破,我們找到如下內(nèi)容:
1、Xcode11 項(xiàng)目中模擬器會(huì)編譯為x86_64别渔,但Xcode12的模擬器基于蘋果Apple Silicon architecture執(zhí)行附迷,需要編譯為arm64運(yùn)行在模擬器上。許多第三方庫(如Firebase哎媚,AFNetworking等)并未提供Xcode12版本的更新支持喇伯,導(dǎo)致報(bào)錯(cuò)。
2拨与、Xcode12 開始移除編譯設(shè)置(Bulid Settings)中的 Valid Architectures的宏定義艘刚。當(dāng)項(xiàng)目使用Xcode12打開時(shí)候,會(huì)在User-Defines(項(xiàng)目的Bulid Settings里面)中自動(dòng)生成VALID_ARCHS宏定義截珍。如果舊項(xiàng)目存在于此沖突的宏定義攀甚,會(huì)導(dǎo)致編譯失敗箩朴。
如何修復(fù)?
第一步:添加 arm64 到 simulator architecture 中秋度。主項(xiàng)目和pod項(xiàng)目都需要炸庞。
在主項(xiàng)目和pod項(xiàng)目的PROJECT的Build Settings中,搜索Excluded Architecture 荚斯,添加 Any iOS Simulator SDK埠居,value填入 arm64
注意:在pod項(xiàng)目的build setting是cocopod自動(dòng)生成的,本次修改在下次更新第三方庫時(shí)候會(huì)被覆蓋事期,可以添加腳本在Podfile中滥壕,防止每次安裝和更新都需要手動(dòng)修改。
post_install do |installer|
? installer.pods_project.build_configurations.each do |config|
? ? config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
? end
end