Xcode12 上使用模擬器編譯項(xiàng)目時(shí),出現(xiàn)錯(cuò)誤。同樣的代碼在Xcode11則不會(huì)有問(wèn)題。
一些錯(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的升級(jí)文檔,我們找到如下內(nèi)容:

1、Xcode11 項(xiàng)目中模擬器會(huì)編譯為x86_64,但Xcode12的模擬器基于蘋果Apple Silicon architecture執(zhí)行,需要編譯為arm64運(yùn)行在模擬器上。許多第三方庫(kù)(如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)生成的,本次修改在下次更新第三方庫(kù)時(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
第二步:在主項(xiàng)目和pod項(xiàng)目的PROJECT的Build Settings中,刪除VALID_ARCHS(整個(gè)刪除,不能只刪除value留下Key)
