今天試着用Xcode 7 beta 3在真機(iOS 8.3)上運行一下咱們的工程,結果發現工程編譯不過。看了下問題,報的是如下錯誤:
html
1
|
ld: ‘/Users
/**/
Framework/SDKs/PolymerPay/Library/mobStat/lib**SDK.a(**ForSDK.o)’ does not contain bitcode. You must rebuild it
with
bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode
for
this
target.
for
architecture arm64
|
獲得的信息是咱們引入的一個第三方庫不包含bitcode。嗯,不知道bitcode是啥,因此就得先看看這貨是啥了。ios
Bitcode是什麼?xcode
找東西嘛,最早想到的固然是先看官方文檔了。在App Distribution Guide – App Thinning (iOS, watchOS)一節中,找到了下面這樣一個定義:app
Bitcode is an intermediate representation of a compiled program. Apps you upload to iTunes Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the store.ide
說的是bitcode是被編譯程序的一種中間形式的代碼。包含bitcode配置的程序將會在App store上被編譯和連接。bitcode容許蘋果在後期從新優化咱們程序的二進制文件,而不須要咱們從新提交一個新的版本到App store上。優化
嗯,看着挺高級的啊。ui
繼續看,在What’s New in Xcode-New Features in Xcode 7中,還有一段以下的描述this
Bitcode. When you archive for submission to the 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 bit executables as necessary.spa
當咱們提交程序到App store上時,Xcode會將程序編譯爲一箇中間表現形式(bitcode)。而後App store會再將這個botcode編譯爲可執行的64位或32位程序。code
再看看這兩段描述都是放在App Thinning(App瘦身)一節中,能夠看出其與包的優化有關了。喵大(@onevcat)在其博客開發者所須要知道的 iOS 9 SDK 新特性中也描述了iOS 9中蘋果在App瘦身中所作的一些改進,你們能夠轉場到那去研讀一下。
Bitcode配置
在上面的錯誤提示中,提到了如何處理咱們遇到的問題:
You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable 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選項:
盜圖,個人應用沒辦法在這個界面顯示bitcode,由於依賴於第三方的庫,而這個庫不支持bitcode,暫時只能設置ENABLE_BITCODE爲NO。
因此,若是咱們的工程須要支持bitcode,則必要要求全部的引入的第三方庫都支持bitcode。我就只能等着公司那些大哥大姐們啥時候提供一個新包給咱們了。
題外話
如上面所說,bitcode是一種中間代碼。LLVM官方文檔有介紹這種文件的格式,有興趣的能夠移步LLVM Bitcode File Format。