在切换到 Xcode 7之后,应用程序的大小从9 MB 增长到60 MB,是否有一个修复?

我一直在回顾 Git 的历史,以找到一个巨大的文件大小变化的原因,但我能找到的唯一真正的原因是从 Xcode 6切换到 Xcode 7 GM。

我发现这些是在 放手构建配置的 档案室操作中创建的 .ipa中文件大小贡献最大的10个文件:

$ unzip -lv Roger\ Release.ipa | sort -k +3nr | head
41802768  Defl:N 16887199  60%  09-14-15 23:47  dc24cdc1  Payload/Roger.app/Frameworks/libswiftCore.dylib
41802400  Defl:N 16886076  60%  09-06-15 18:33  f939ea6a  SwiftSupport/iphoneos/libswiftCore.dylib
11184032  Defl:N  5915625  47%  09-14-15 23:48  6ceac4a2  Payload/Roger.app/Roger
6399584  Defl:N  2670275  58%  09-14-15 23:47  0ac52d3f  Payload/Roger.app/Frameworks/libPhoneNumber_iOS.framework/libPhoneNumber_iOS
5410384  Defl:N  2334189  57%  09-14-15 23:47  7a8cb03f  Payload/Roger.app/Frameworks/Alamofire.framework/Alamofire
4521904  Defl:N  2292789  49%  09-14-15 23:47  95da0882  Payload/Roger.app/Frameworks/FBSDKCoreKit.framework/FBSDKCoreKit
4731552  Defl:N  1926357  59%  09-14-15 23:48  e05337de  Payload/Roger.app/Frameworks/libswiftFoundation.dylib
4731168  Defl:N  1925355  59%  09-06-15 18:33  19a5c3c4  SwiftSupport/iphoneos/libswiftFoundation.dylib
2659232  Defl:N  1232897  54%  09-14-15 23:47  1a53a401  Payload/Roger.app/Frameworks/AFNetworking.framework/AFNetworking
1196624  Defl:N   545343  54%  09-14-15 23:47  19a063cb  Payload/Roger.app/Frameworks/Bolts.framework/Bolts

到目前为止,最大的文件是两个(略有不同) libswiftCore.dylib文件,总共超过32 MB。在 Xcode 6构建的包中,这两个文件总共只有3 MB。

所以问题 # 1是: 为什么 Swift 核心文件在那里两次? (嵌入式内容包含快速代码被设置为 没有)。

第二个问题是: 发生了什么? 为什么 Swift 的核心大小增加了15MB? 这是永久性的吗?

附注:

  • 这是一个完全是 Objective-C 的项目,但现在主要是 Swift。
  • 该项目使用设置了 use_frameworks!的 CocoaPods。
  • 我已经确认了 TestFlight 在多个设备和 iOS 版本上的实际下载大小,范围在30-60MB 之间(可能是应用程序切片造成的差异)。以前是9MB。
31804 次浏览

Most likely caused by BitCode, I have seen the same growth however once deployed from the App Store the app size hasn't actually grown.

You can disable BitCode in your app and the other targets as well and you should see a shrinkage.

We also had this problem with Swift 1.2. See How to prevent SwiftSupport libraries to be included twice for my original question about this same issue.

I am pretty sure this is a toolchain issue.

It is expected that the size of the swift dylibs, and your own code, will be significantly larger in the .xcarchive, and when you export for store distribution, due to the inclusion of bitcode. This additional size will not be reflected in what actually gets delivered to your users, so it should not be a problem. When you submit your app to the store, the store will process it to strip out the bitcode, and that processed version of the IPA is what your users will download.

If you do any type of export from your archive except a store export (e.g. save for ad-hoc deployment), we will locally strip out the bitcode (and even recompile your binaries from bitcode first, if you leave that option checked in the export workflow, to recreate what will happen on the store), so you can see how big your app will actually be. TestFlight will also strip bitcode for you and show you your true app size.

You should also be aware that your app's size can also be reduced via app thinning, which you can read about at https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html. You will likely want to perform an ad-hoc export to see the size of each thinned variant of your app anyway.

Embedded Bitcode is the reason.

Assuming you don't want to disable ENABLE_BITCODE, you can strip the debug symbols.

See http://oguzbastemur.blogspot.com/2015/09/xcode-7-and-increaded-binary-size.html as stripping debug symbols away before embedding bitcode is one of the options you can do.

I've been testing a lot of settings and combinations and it seems the file size of bundles created by Xcode 7 vary a lot depending on both the device and the version of iOS. Also, the TestFlight builds are now huge compared to before, but the good news is that once on the App Store there hasn't been a huge increase (although I am seeing about 1–2 MB added to the bundle size compared to before).

Here's a few samples to show variance between TestFlight, App Store and devices:

TestFlight, iPhone 5s on iOS 9.1
35.6 MB

TestFlight, iPhone 6 on iOS 8.4.1
70.1 MB

App Store
11.8 MB

The App Store size was identical on all devices I tested. I haven't tested it on iPhone 6 Plus though, it's very possible that the bundle size would be larger since it uses @3x assets.