Skip to content

Commit

Permalink
增加对App Thinning的描述【4.bitcode】
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenYilong committed Sep 18, 2015
1 parent 4ebfa80 commit 3b41e07
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,15 @@ iOS9以后,企业级分发ipa包将遭到与Mac上dmg安装包一样的待遇
[14]: https://i.imgur.com/PXM235L.gif


##4.Bitcode(通俗解释:在线版安卓ART模式)
##4.Bitcode

【前言】未来, Watch 应用必须包含 bitcode ,iOS不强制,Mac OS不支持。
但最坑的一点是: Xcode7 及以上版本会默认开启 bitcode 。

什么是 bitcode ?

通俗解释:在线版安卓ART模式。

Apple 官方文档--[ ***App Distribution Guide – App Thinning (iOS, watchOS)*** ](https://developer.apple.com/library/prerelease/ios/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html#//apple_ref/doc/uid/TP40012582-CH35)是这样定义的:

> 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.
Expand All @@ -870,11 +872,44 @@ Apple 官方文档--[ ***App Distribution Guide – App Thinning (iOS, watchOS)*
> 当我们提交程序到 App Store上时, Xcode 会将程序编译为一个中间表现形式( bitcode )。然后 App store 会再将这个 bitcode 编译为可执行的64位或32位程序。

再看看这两段描述都是放在App Thinning(App瘦身)一节中,可以看出其与包的优化有关了。喵大(@onevcat)在其博客 [《开发者所需要知道的 iOS 9 SDK 新特性》](http://onevcat.com/2015/06/ios9-sdk/) 中也描述了iOS 9中苹果在App瘦身中所做的一些改进,大家可以转场到那去研读一下。
再看看这两段描述都是放在App Thinning(App瘦身)一节中,可以看出其与包的优化有关了。

App Thinning 官方文档解释如下:


> The App Store and operating system optimize the installation of iOS and watchOS apps by tailoring app delivery to the capabilities of the user’s particular device, with minimal footprint. This optimization, called app thinning, lets you create apps that use the most device features, occupy minimum disk space, and accommodate future updates that can be applied by Apple. Faster downloads and more space for other apps and content provides a better user experience.

开发者都知道,当前 iOS App 的编译打包方式是把适配兼容多个设备的执行文件及资源文件合并一个文件,上传和下载的文件则包含了所有的这些文件,导致占用较多的存储空间。

App Thinning是一个关于节省iOS设备存储空间的功能,它可以让iOS设备在安装、更新及运行App等场景中仅下载所需的资源,减少App的占用空间,从而节省设备的存储空间。

根据Apple官方文档的介绍,App Thinning主要有三个机制:


1. Slicing

开发者把App安装包上传到AppStore后,Apple服务会自动对安装包切割为不同的应用变体(App variant),当用户下载安装包时,系统会根据设备型号下载安装对应的单个应用变体。

2. On-Demand Resources

ORD(随需资源)是指开发者对资源添加标签上传后,系统会根据App运行的情况,动态下载并加载所需资源,而在存储空间不足时,自动删除这类资源。

3. Bitcode
开启Bitcode编译后,可以使得开发者上传App时只需上传Intermediate Representation(中间件),而非最终的可执行二进制文件。 在用户下载App之前,AppStore会自动编译中间件,产生设备所需的执行文件供用户下载安装。

(喵大(@onevcat)在其博客 [《开发者所需要知道的 iOS 9 SDK 新特性》](http://onevcat.com/2015/06/ios9-sdk/) 中也描述了iOS 9中苹果在App瘦身中所做的一些改进,大家可以转场到那去研读一下。)


其中,Bitcode的机制可以支持动态的进行App Slicing,而对于Apple未来进行硬件升级的措施,此机制可以保证在开发者不重新发布版本的情况下而兼容新的设备。

Bitcode 是一种中间代码,那它是什么格式的呢? LLVM 官方文档有介绍这种文件的格式: [ ***LLVM Bitcode File Format*** ](http://llvm.org/docs/BitCodeFormat.html#llvm-bitcode-file-format)

如果你的应用也准备启用 Bitcode 编译机制,就需要注意以下几点:

1. Xcode 7默认开启 Bitcode ,如果应用开启 Bitcode,那么其集成的其他第三方库也需要是 Bitcode 编译的包才能真正进行 Bitcode 编译
2. 开启 Bitcode 编译后,编译产生的 `.app` 体积会变大(中间代码,不是用户下载的包),且 `.dSYM` 文件不能用来崩溃日志的符号化(用户下载的包是 Apple 服务重新编译产生的,有产生新的符号文件)
3. 通过 Archive 方式上传 AppStore 的包,可以在Xcode的Organizer工具中下载对应安装包的新的符号文件


如何适配?
Expand All @@ -894,7 +929,7 @@ Xcode 7 + 会开启 Bitcode。

也就是说,也两种方法适配:

方法一:更新library使包含Bitcode,否则会出现以下中的警告;
方法一:更新 library 使包含 Bitcode ,否则会出现以下中的警告;

> (null): URGENT: all bitcode will be dropped because
> '/Users/myname/Library/Mobile
Expand Down Expand Up @@ -932,7 +967,7 @@ clang: error: linker command failed with exit code 1 (use -v to see invocation)



如果我们开启了bitcode,在提交包时,下面这个界面也会有个 bitcode 选项:
如果我们开启了 bitcode ,在提交包时,下面这个界面也会有个 bitcode 选项:

![enter image description here](http://i60.tinypic.com/5b2q7m.jpg)

Expand Down

0 comments on commit 3b41e07

Please sign in to comment.