前言
因為使用需要,更換了一臺M1芯片的mac電腦,在安裝好各種pod、git、xcode環境后,其他項目在兩臺mac上都能運行模擬器,而另一個項目在intel芯片的mac電腦能正常在模擬器上運行,而在M1芯片上就會報錯
ld: library not found for -lPod-xxx
, 查找了很多文章都沒解決,然后使用真機運行就能完整運行,再查找文章發現就是M1芯片導致,需要在podfile里更新一下配置
發現某些pod會導致這個問題,比如:pod 'Firebase/Analytics', '~>6.7.0'
步驟一,在podfile文件里配置如下
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
步驟二,注釋掉podfile里的use_frameworks!
完整多targe的demo如下:
platform :ios, '12.0'
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
targetsArray = ['aaa', 'bbb', 'ccc']
targetsArray.each do |t|
target t do
pod 'AFNetworking'
pod 'SDWebImage'
pod 'Firebase/Analytics', '~>6.7.0'
....
end
end
完整單targe的demo如下:
platform :ios, '12.0'
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
target 'Hello' do
# use_frameworks!
# Pods for Hello
pod 'AFNetworking'
pod 'Firebase/Analytics', '~>6.7.0'
target 'HelloTests' do
inherit! :search_paths
# Pods for testing
end
target 'HelloUITests' do
# Pods for testing
end
end
步驟三,Build Settings
->Architectures
->Excluded Architectures
-> Debug
->Any SDK
->arm64
如下圖
截屏2022-02-05 下午11.40.01.png
參考:https://narlei.com/development/apple-m1-xcode-error-when-build-in-simulator/