Just My Life & My Work

[iOS][watchOS] 位元代碼 (Bitcode)

還沒看到有高人翻譯,所以我暫且稱之為位元代碼 (Bitcode),看來我被中國化了⋯⋯台灣用語應為位元程式碼!其實在WWDC 2015,Apple只是提到它,並沒有詳細介紹它架構與運作,謎樣地描述什麼是位元代碼 (Bitcode):

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.

Xcode hides symbols generated during build time by default, so they are not readable by Apple. Only if you choose to include symbols when uploading your app to iTunes Connect would the symbols be sent to Apple. You must include symbols to receive crash reports from Apple.

Note: For iOS apps, bitcode is the default, but optional. If you provide bitcode, all apps and frameworks in the app bundle need to include bitcode. For watchOS apps, bitcode is required.



也就是說,之前還沒有Bitcode時,我們提交app時是直接安裝到裝置上的ipa檔,現在Xcode中的LLVM會先編譯成中間碼 (intermediate representation of a compiled program),再上傳到App Store,使用者若想下載來安裝,則會取得適合使用者裝置的ipa,也就是說Apple會幫開發者編譯各種裝置適合的ipa。

TNW News有進一步解釋:

what is Bitcode?
That’s a big question. First, you need to know what a Low Level Virtual Machine (LLVM) is. LLVM is a library that’s used to compile code down into intermediate or machine code. LLVM is used to build many compilers and languages you’re probably familiar with.

There are two parts to LLVM. First, you have a “front end” language that you use to build your app, like Objective-C, Swift, Python or Ruby and a “back end” which compiles that app down to machine code.

An “intermediate” language like Bitcode is an abstract encoding of an app that can be used to re-compile it in different ways, given a set of instructions.

Bitcode uses the LLVM to take your app’s code, converts it into Bitcode and knows how to turn that into an executable app, based on the instruction set it’s given.

To simplify, this architecture means Apple can simply add support for new CPUs to the “back end” on the App Store, which will show Bitcode how to compile down to new architecture.


壞的方面,開發者而言,轉換期就在喊痛,因為在Xcode啟用後就編譯失敗,說什麼使用的第三方套件也要用Bitcode來編譯,於是我們要等第三方套件作者使用Bitcode編譯來更新套件⋯⋯若直接關掉Bitcode來編譯就會成功而非常省事!然而若我專案有用watchOS,就一定要使用Bitcode來編譯⋯⋯於是我暫時放棄更新公司產品watch app。

對於謎樣的Bitcode,現在使用Xcode 7有兩種選擇:

  1. 更新library使包含Bitcode
  2. 關閉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. Note: This will be an error in the future.

bitcode enable



Comments on: "[iOS][watchOS] 位元代碼 (Bitcode)" (1)

  1. […] 2015年有介紹過位元代碼 (Bitcode),儘管沒有很關注它的發展,偶爾卻會在編譯的時候有Bitcode問題。 […]



WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )


您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


%d 位部落客按了讚: