今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Xcode14編譯失敗修改

背景#

升級 Xcode 14 後,項目編譯失敗修改,共修改了兩種編譯錯誤:

  • 一種是 bundle code sign error,Xcode 14 needs selected Development Team for Pod Bundles
  • 一種是Module compiled with Swift 5.6.1 cannot be imported by the Swift 5.7 compiler

其中第一種比較容易解決,第二種稍微麻煩點,解決方案如下:

解決#

Xcode 14 bundle code sign error#

這個的解決方案,直接 Google,第一个 stackoverflow 的鏈接是Xcode 14 needs selected Development Team for Pod Bundles,這裡面給出的解決方法是,在 Podfile 裡增加下面代碼,然後運行Pod install,設置 Pod 庫的DEVELOPMENT_TEAM是開發者賬號的 team。

筆者有兩個項目,其中一個是 Swift 為主,用下面的設置方法試了,可以解決。要注意的是如果項目有多個 target,target 的開發者 team 又不同时需要區分設置,可參考下面註釋的代碼。

post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings["DEVELOPMENT_TEAM"] = "Your Team ID"
#            if target.name == 'test'
#            config.build_settings["DEVELOPMENT_TEAM"] = "Your Team ID"
#          else
#            config.build_settings["DEVELOPMENT_TEAM"] = "Your Another Team ID"
#          end
         end
    end
  end
end

但是,筆者另外一個 OC 的項目中,按照這個方法設置,卻一直不行,也是神奇,所以又找了另一個解決方案,來自 CocoaPods 的 issue,Xcode 14 build failed with manual code sign and app resource bundles ,其中的解決方案有一種是設置CODE_SIGN_IDENTIFY為空,如下:

post_install do |installer|
  installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
          config.build_settings['CODE_SIGN_IDENTITY'] = ''
      end
  end
end

這種避免了區分設置DEVELOPMENT_TEAM的情況,在兩個項目裡設置如上代碼,都可以編譯成功。

Module compiled with Swift 5.6.1 cannot be imported by the Swift 5.7 compiler#

這個錯誤直接一看是 Swift 版本不兼容,再仔細看錯誤,應該看到提示的庫是三方 SDK 的,對於筆者的項目來說是使用 Carthage 集成的 SDK 的。昂,應該是使用 Carthage 編譯的 xcframeworks 導致的,所以就去重新編譯 xcframeworks,但是編譯的時候,Moya庫一直編譯失敗,手動去編譯Moya發現編譯到真機成功,編譯到模擬器就失敗,報錯Could not find module 'Alamofire' for target 'x86_64-apple-ios-simulator';,難搞,這個地方找解決方法找了好久,最後還是在Using Carthage with Xcode 12這裡看到了解決方法,這個方法可以remove arm64 simulator architecture from compiled framework

解決方法如下:

remove arm64 simulator architecture from compiled framework

順便說一下,筆者的電腦並不是Macs running Apple Silicon,是 intel 芯片的電腦。

參考#

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。