ld: building for iOS Simulator, but linking in object file built for iOS, file 'xxx/Pods/mob_sharesdk/ShareSDK/Support/PlatformConnector/QQConnector.framework/QQConnector' for architecture arm64
上篇文章講了M1芯片安裝CocoaPods問題遭笋,剛剛配置好pods環(huán)境管怠。新的問題又出現(xiàn)了:運行項目時坛吁,編譯不通過凤薛,模擬器報錯收厨,出現(xiàn)了上面的問題缴啡,而真機是可以運行的!Xcode版本12.4骂际,模擬器是iOS14.4疗琉。而且在我電腦上(15款Macbook Pro)模擬器可以運行,真機也可以運行歉铝,新買的電腦M1芯片的運行卻報錯盈简。
看了網(wǎng)上的內(nèi)容,大致有幾種方案都試了還是不行太示!
- 搜索VALID_ARCHS字段柠贤,將里面的值去掉或加上
x86_64
类缤,或?qū)⒄麄€字段刪除坚俗。我搜索之后卻沒有個這值降允。 - 在Build Settings下Architecture中Excluded Architecture 屬性加上 arm64幢尚,并且Build Active Architecture Only 設置為 NO尉剩。
- 刪除.xcworkspace和Podfile.lock文件础倍,重新
pod install
;刪除Xcode緩存,點擊訪達Shift + command + G進入,輸入~/Library/Developer/Xcode/DerivedData
,刪除里面的全部文件芽腾;多次重啟Xcode阴绢。
在進行第二種方法的時候腺兴,出現(xiàn)以下錯誤
Cocoapods ld: library not found for -lPods-Projectname
解決方法(附件參考文章1)是在Build Phases下Link Binary With Libraries刪除libPods-Projectname.a闰蚕。然后出現(xiàn)缺少x86_64和i386涩哟,在arm64那加上這兩個還是不可以诗鸭,于是放棄了這種方法染簇!
以上方法都試了,都不行强岸!感覺是pods設置的問題锻弓,多次注掉Podfile文件里的庫,然后執(zhí)行pod install
蝌箍,還是報錯青灼!
然后找到了一篇文章(附件參考文章2)中的解決方法
在Excluded Architecture下增加 Any iOS Simulator SDK屬性,值是arm64妓盲,并且Build Active Architecture Only 都設置為 YES(NO的話也運行不了)杂拨。
Podfile或Podspec文件中設置
- Podfile文件中增加代碼:
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
然后執(zhí)行pod install
,執(zhí)行后會自動在Podspec中添加上面的pod設置代碼悯衬。
- 在Podspec文件中添加pod設置代碼:
s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
然后執(zhí)行pod install
到這里模擬器就可以運行了弹沽,經(jīng)測試真機也能正常運行。不像網(wǎng)上說的還要改回來真機才可以運行筋粗!
- 但是在執(zhí)行
pod install
的時候終端出現(xiàn)了以下警告:
[!] The `HaoYaoZaiXianB [Debug]` target overrides the `EXCLUDED_ARCHS[sdk=iphonesimulator*]` build setting defined in `Pods/Target Support Files/Pods-HaoYaoZaiXianB/Pods-HaoYaoZaiXianB.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `HaoYaoZaiXianB [Release]` target overrides the `EXCLUDED_ARCHS[sdk=iphonesimulator*]` build setting defined in `Pods/Target Support Files/Pods-HaoYaoZaiXianB/Pods-HaoYaoZaiXianB.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
于是按照提示在Excluded Architecture下Debug和Release后面值增加$(inherited)
策橘。然后執(zhí)行pod install
就沒有警告了!
我又按照文章里的其他方法試了娜亿,也不可以丽已。最后pod環(huán)境都搞壞了,出現(xiàn)錯誤
failed to read asset tags: Error Domain=NSPOSIXErrorDomain Code=9 "Bad file
只能刪掉.xcworkspace和Podfile.lock文件买决,重新pod install
沛婴。果然重新恢復正常吼畏!
到這里就基本結(jié)束了,總結(jié)一下方法:
- Excluded Architecture中Debug和Release添加Any iOS Simulator SDK屬性嘁灯,添加值arm64并且設置Active Architecture都為YES
- Podfile文件添加設置泻蚊,在指定source源后面(target前添加)添加
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
- Excluded Architecture中Debug和Release后面值增加
$(inherited)
,去除pod install
警告
原因在參考文章里有旁仿,因為是英文的(本人英文能力有限)藕夫,具體原因我也是一知半解,只知道是M1芯片(與Intel芯片架構(gòu)不同)才有這個問題枯冈!至于后續(xù)這樣設置會出現(xiàn)其他問題嗎,我也不清楚办悟!但是項目卻是可以正常運行的尘奏,而且真機調(diào)試的時候不用刪除設置,省去了很多麻煩病蛉!
參考文章: