building for iOS Simulator, but linking in object file built for iOS

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環境。新的問題又出現了:運行項目時,編譯不通過,模擬器報錯,出現了上面的問題,而真機是可以運行的!Xcode版本12.4,模擬器是iOS14.4。而且在我電腦上(15款Macbook Pro)模擬器可以運行,真機也可以運行,新買的電腦M1芯片的運行卻報錯。
看了網上的內容,大致有幾種方案都試了還是不行!

  1. 搜索VALID_ARCHS字段,將里面的值去掉或加上x86_64,或將整個字段刪除。我搜索之后卻沒有個這值。
  2. 在Build Settings下Architecture中Excluded Architecture 屬性加上 arm64,并且Build Active Architecture Only 設置為 NO。
  3. 刪除.xcworkspace和Podfile.lock文件,重新pod install;刪除Xcode緩存,點擊訪達Shift + command + G進入,輸入~/Library/Developer/Xcode/DerivedData,刪除里面的全部文件;多次重啟Xcode。

在進行第二種方法的時候,出現以下錯誤

Cocoapods ld: library not found for -lPods-Projectname

解決方法(附件參考文章1)是在Build Phases下Link Binary With Libraries刪除libPods-Projectname.a。然后出現缺少x86_64和i386,在arm64那加上這兩個還是不可以,于是放棄了這種方法!
以上方法都試了,都不行!感覺是pods設置的問題,多次注掉Podfile文件里的庫,然后執行pod install,還是報錯!

然后找到了一篇文章(附件參考文章2)中的解決方法

  1. 在Excluded Architecture下增加 Any iOS Simulator SDK屬性,值是arm64,并且Build Active Architecture Only 都設置為 YES(NO的話也運行不了)。

  2. 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

然后執行pod install,執行后會自動在Podspec中添加上面的pod設置代碼。

  • 在Podspec文件中添加pod設置代碼:
s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

然后執行pod install

到這里模擬器就可以運行了,經測試真機也能正常運行。不像網上說的還要改回來真機才可以運行!
  • 但是在執行pod install的時候終端出現了以下警告:
[!] 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)。然后執行pod install就沒有警告了!
我又按照文章里的其他方法試了,也不可以。最后pod環境都搞壞了,出現錯誤
failed to read asset tags: Error Domain=NSPOSIXErrorDomain Code=9 "Bad file
只能刪掉.xcworkspace和Podfile.lock文件,重新pod install。果然重新恢復正常!

到這里就基本結束了,總結一下方法:
  1. Excluded Architecture中Debug和Release添加Any iOS Simulator SDK屬性,添加值arm64并且設置Active Architecture都為YES
  2. 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
  1. Excluded Architecture中Debug和Release后面值增加$(inherited),去除pod install警告

原因在參考文章里有,因為是英文的(本人英文能力有限),具體原因我也是一知半解,只知道是M1芯片(與Intel芯片架構不同)才有這個問題!至于后續這樣設置會出現其他問題嗎,我也不清楚!但是項目卻是可以正常運行的,而且真機調試的時候不用刪除設置,省去了很多麻煩!

參考文章:

  1. stackoverflow參考文章1
  2. stackoverflow參考文章2
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容