Just a Computer Graphics Studio & My Life

[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

也就是說,之前還沒有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.

這個變化當然有好有壞,對於開發者來說,未來若硬體架構若改變(比如先前從32bit變為64bit),不用再重新編譯,Apple會幫開發者編譯好;對於使用者來說,我只要下載適合我裝置的ipa檔來安裝,它已經被優化過(如檔案容量降低),可以發揮裝置最好的使用者體驗!對於Apple來說,我可以拿到開發者原始碼:P~未來可以拷貝優良app變成內建app

壞的方面,開發者而言,轉換期就在喊痛,因為在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

未來我們就來拭目以待,Apple要怎麼玩Bitcode:P~

參考:

廣告

發表留言

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

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

Twitter picture

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

Facebook照片

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

Google+ photo

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

連結到 %s

標籤雲

%d 位部落客按了讚: