iOS中Bitcode的介紹及配置 ?(轉載自 小麥麥子)
我又加入了我的 自己的問題 ,很糾結的
今天在一個iOS培訓網站上看到一篇關于第三方庫不包含bitcode就會報錯的文章,感覺剖析得很詳細,分享出來,希望可以對iOS初入門者有所幫助。下面我們就一起來看看吧。
用Xcode 7 beta 3在真機(iOS 8.3)上運行一下工程,結果發現工程編譯不過。看了下問題,報的是以下錯誤:
ld: ‘/Users/**/Framework/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.
說的是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選項:
所以,如果我們的工程需要支持bitcode,則必要要求所有引入的第三方庫都支持bitcode。
通過本文對bitcode的概念及配置情況的簡要介紹,希望iOS開發人員在工程運行中遇到類似的情況,可以根據上文的介紹更有效的找到原因并及時處理。
在做靜態庫的制作 ?或者是 framWork 的編譯時我們也會 注意bitcode的關閉;我們將會在下一篇介紹;