打包時 bitcode 錯誤

用Xcode 7.2 在真機(iOS 7.1)上運行一下工程,結果發現工程編譯不過。看了下問題,報的是以下錯誤:

ld: ‘/UsersFramework/SDKs/PolymerPay/Library/mobStat/lib**SDK.a(**ForSDK.o)’does not contain bitcode. You must rebuild it with bitcode enabled (Xcodesetting ENABLE_BITCODE), obtain an updated library from the vendor, or disablebitcode for this target. for architecture arm64

得到的信息是引入的一個第三方庫不包含bitcode。

Bitcode是個什麼鬼?

查閱了一下官方文檔,在App

Distribution Guide–App Thinning (iOS, watchOS)一節中,找到了下面這樣一個定義:

Bitcode is an intermediate representationof a compiled program. Apps you upload to iTunes Connect that contain bitcodewill be compiled and linked on the App Store. Including bitcode will allowApple to re-optimize your app binary in the future without the need to submit anew version of your app to the store.

eg:

說的是bitcode是被編譯程序的一種中間形式的代碼。包含bitcode配置的程序將會在App store上被編譯和鏈接。bitcode允許蘋果在後期重新優化程序的二進制文件,而不需要重新提交一個新的版本到App store上。

而在What’s New in Xcode-New Features in Xcode 7中,還有一段如下的描述:

Bitcode. When you archive for submission tothe App Store, Xcode will compile your app into an intermediate representation.The App Store will then compile the bitcode down into the 64 or 32 bitexecutables as necessary.

當提交程序到App store上時,Xcode會將程序編譯爲一箇中間表現形式(bitcode)。然後App store會再將這個botcode編譯爲可執行的64位或32位程序。

再看看這兩段描述,都是放在App Thinning(App瘦身)一節中,可以看出其與包的優化有關了。

Bitcode配置

在上面的錯誤提示中,提到了如何處理我們遇到的問題:

You must rebuild it with bitcode enabled(Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, ordisable bitcode for this target. for architecture arm64

要麼讓第三方庫支持,要麼關閉target的bitcode選項。

實際上,在Xcode 7中,我們新建一個iOS程序時,bitcode選項默認是設置爲YES的。我們可以在”Build Settings”->”Enable Bitcode”選項中看到這個設置。不過,我們現在需要考慮的是三個平臺:iOS,Mac OS,watchOS。

對於iOS,bitcode是可選的;對於watchOS,bitcode是必須的;而Mac OS是不支持bitcode。

如果我們開啓了bitcode,在提交包時,下面這個界面也會有個bitcode選項:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章