今天試著用Xcode 7 beta 3在真機(iOS 8.3)上運行一下我們的工程肯腕,結(jié)果發(fā)現(xiàn)工程編譯不過蔬浙》裎常看了下問題盖袭,報的是以下錯誤:
1
ld: ‘/Users
//
Framework/SDKs/PolymerPay/Library/mobStat/libSDK.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是啥可很,所以就得先看看這貨是啥了。
Bitcode是什么凰浮?
找東西嘛我抠,最先想到的當然是先看官方文檔了。在App Distribution Guide – App Thinning (iOS, watchOS)一節(jié)中导坟,找到了下面這樣一個定義:
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.
說的是bitcode是被編譯程序的一種中間形式的代碼屿良。包含bitcode配置的程序?qū)贏pp store上被編譯和鏈接。bitcode允許蘋果在后期重新優(yōu)化我們程序的二進制文件惫周,而不需要我們重新提交一個新的版本到App store上尘惧。
嗯,看著挺高級的啊递递。
繼續(xù)看喷橙,在What’s New in Xcode-New Features in Xcode 7中,還有一段如下的描述
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.
當我們提交程序到App store上時登舞,Xcode會將程序編譯為一個中間表現(xiàn)形式(bitcode)贰逾。然后App store會再將這個botcode編譯為可執(zhí)行的64位或32位程序。
再看看這兩段描述都是放在App Thinning(App瘦身)一節(jié)中菠秒,可以看出其與包的優(yōu)化有關(guān)了疙剑。喵大(@onevcat)在其博客開發(fā)者所需要知道的 iOS 9 SDK 新特性中也描述了iOS 9中蘋果在App瘦身中所做的一些改進氯迂,大家可以轉(zhuǎn)場到那去研讀一下。
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
要么讓第三方庫支持嚼蚀,要么關(guān)閉target的bitcode選項。
實際上在Xcode 7中管挟,我們新建一個iOS程序時轿曙,bitcode選項默認是設(shè)置為YES的。我們可以在”Build Settings”->”Enable Bitcode”選項中看到這個設(shè)置僻孝。
不過导帝,我們現(xiàn)在需要考慮的是三個平臺:iOS,Mac OS穿铆,watchOS您单。
對應(yīng)iOS,bitcode是可選的荞雏。
對于watchOS睹限,bitcode是必須的。
Mac OS不支持bitcode讯檐。
如果我們開啟了bitcode,在提交包時染服,下面這個界面也會有個bitcode選項:
盜圖别洪,我的應(yīng)用沒辦法在這個界面顯示bitcode,因為依賴于第三方的庫柳刮,而這個庫不支持bitcode挖垛,暫時只能設(shè)置ENABLE_BITCODE為NO。
所以秉颗,如果我們的工程需要支持bitcode痢毒,則必要要求所有的引入的第三方庫都支持bitcode。我就只能等著公司那些大哥大姐們啥時候提供一個新包給我們了蚕甥。
題外話
如上面所說哪替,bitcode是一種中間代碼。LLVM官方文檔有介紹這種文件的格式菇怀,有興趣的可以移步LLVM Bitcode File Format凭舶。