上周五買(mǎi)了新的MacBook pro,從頭開(kāi)始配置開(kāi)發(fā)環(huán)境,下載了Xcode26.2,剛開(kāi)始一切都正常,但是編譯Destinations始終沒(méi)有可用的模擬器,后來(lái)發(fā)現(xiàn)是項(xiàng)目的Building Settings里的Excluded Architectures里面設(shè)置的arm64,apple silicon芯片的模擬器都是arm64的,導(dǎo)致沒(méi)有可用的模擬器,但是項(xiàng)目依賴太多,很多舊的庫(kù)并沒(méi)有更新沒(méi)辦法把這個(gè)刪掉,后來(lái)又查了很多Apple的文檔,發(fā)現(xiàn)xcode現(xiàn)在會(huì)有兩種模擬器運(yùn)行時(shí),一種universal,一種arm64,而默認(rèn)的是arm64,因此我只能命令行下載universal類型的模擬器運(yùn)行時(shí)(rosetta),具體的命令行:
xcodebuild -downloadPlatform <iOS|watchOS|tvOS|visionOS> [-exportPath <destinationpath> -buildVersion <osversion> -architectureVariant <universal|arm64>]
下載以后,清除已有的模擬器:
# 1. 列出所有模擬器,確認(rèn)無(wú)效模擬器的UUID和狀態(tài)
xcrun simctl list devices
# 2. 刪除這個(gè)無(wú)效的模擬器(替換為你的UUID)
xcrun simctl delete 75F6395D-A60F-4442-BF5F-D56A4B2B7A75
# 3. 若提示“設(shè)備不存在”,先清理所有不可用模擬器
xcrun simctl delete unavailable
# 4. 重置CoreSimulator服務(wù),確保緩存同步
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService
launchctl start com.apple.CoreSimulator.CoreSimulatorService
然后安裝此模擬器運(yùn)行時(shí)
xcrun simctl runtime add "~/Downloads/xxx.dmg"
參考文檔:https://developer.apple.com/documentation/technotes/tn3117-resolving-build-errors-for-apple-silicon
參考文檔:https://developer.apple.com/documentation/xcode/downloading-and-installing-additional-xcode-components?f_link_type=f_linkinlinenote&flow_extra=eyJpbmxpbmVfZGlzcGxheV9wb3NpdGlvbiI6MCwiZG9jX3Bvc2l0aW9uIjowLCJkb2NfaWQiOiI4MGU5OGNhODQ2Yzc1OTZkLTIxMzBlYjU1NWYzOTM5NWIifQ%3D%3D