ios 切换到 Xcode 7 后,应用程序大小从 9 MB 增长到 60 MB,是否有解决方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32588757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
After switching to Xcode 7, app size grew from 9 MB to 60 MB, is there a fix?
提问by Blixt
I've been going backwards in Git history to find the cause of a humongous file size change, but the only real reason I can find is the switch from Xcode 6 to Xcode 7 GM.
我一直在 Git 历史中倒退,以找出导致文件大小发生巨大变化的原因,但我能找到的唯一真正原因是从 Xcode 6 切换到 Xcode 7 GM。
I've found that these are the top 10 file size contributors in an .ipa
created from the Archiveoperation on a Releasebuild configuration:
我发现这些是.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
By far the largest files are the two (slightly different) libswiftCore.dylib
files, which total over 32 MB. In the bundle built by Xcode 6 these two files totaled only 3 MB.
到目前为止,最大的文件是两个(略有不同)的libswiftCore.dylib
文件,总大小超过 32 MB。在 Xcode 6 构建的包中,这两个文件总共只有 3 MB。
So question #1 is: Why are the Swift core files there twice? (Embedded Content Contains Swift Codeis set to No).
所以问题 #1 是:为什么 Swift 核心文件有两次?(嵌入式内容包含 Swift 代码设置为No)。
And question #2 is: What happened? Why did the Swift core size increase by 15 MB? Is this permanent?
问题 2 是:发生了什么?为什么 Swift 内核大小增加了 15 MB?这是永久的吗?
Some additional notes:
一些补充说明:
- This is a project that was entirely Objective-C but is now mostly Swift. The Defines Modulesetting is set to Yes.
- The project uses CocoaPods with
use_frameworks!
set. - I've confirmed the actual download size from TestFlight on multiple devices and iOS versions and it's in the range 30–60 MB (presumably the difference is due to app slicing). It used to be 9 MB.
- 这是一个完全是 Objective-C 的项目,但现在主要是 Swift。该定义模块设置为是。
- 该项目使用带有
use_frameworks!
set 的CocoaPods 。 - 我已经在多个设备和 iOS 版本上确认了来自 TestFlight 的实际下载大小,它在 30-60 MB 的范围内(大概是由于应用程序切片造成的)。它曾经是 9 MB。
回答by David Rothera
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.
最有可能是由 BitCode 引起的,我看到了同样的增长,但是一旦从 App Store 部署,应用程序的大小实际上并没有增长。
You can disable BitCode in your app and the other targets as well and you should see a shrinkage.
您可以在您的应用程序和其他目标中禁用 BitCode,您应该会看到缩小。
回答by Blixt
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).
我一直在测试很多设置和组合,似乎由 Xcode 7 创建的包的文件大小因设备和 iOS 版本而异。此外,与以前相比,TestFlight 版本现在非常庞大,但好消息是,在 App Store 上架后并没有大幅增加(尽管与以前相比,我看到捆绑包大小增加了大约 1-2 MB) .
Here's a few samples to show variance between TestFlight, App Store and devices:
以下是一些示例,用于显示 TestFlight、App Store 和设备之间的差异:
TestFlight, iPhone 5s on iOS 9.1
35.6 MB
TestFlight,iOS 9.1 上的 iPhone 5s
35.6 MB
TestFlight, iPhone 6 on iOS 8.4.1
70.1 MB
TestFlight,iOS 8.4.1 上的 iPhone 6
70.1 MB
App Store
11.8 MB
应用商店
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.
App Store 大小在我测试的所有设备上都是相同的。不过,我还没有在 iPhone 6 Plus 上对其进行过测试,因为它使用了 @3x 资产,所以捆绑包的大小很可能会更大。
回答by Rick Ballard
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.
由于包含 bitcode,预计 .xcarchive 中的 swift dylib 和您自己的代码的大小将明显更大,并且当您导出商店分发时。这个额外的大小不会反映在实际交付给您的用户的内容中,因此应该不成问题。当您将应用程序提交到商店时,商店将对其进行处理以去除位代码,并且该 IPA 的处理版本就是您的用户将下载的内容。
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.
如果您从存档中进行任何类型的导出,除了存储导出(例如保存为临时部署),我们将在本地去除位代码(甚至首先从位代码重新编译您的二进制文件,如果您在导出中选中该选项工作流,重新创建将在商店中发生的事情),因此您可以看到您的应用程序实际上有多大。TestFlight 还会为您去除位码并显示您的真实应用大小。
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.
您还应该注意,您的应用程序的大小也可以通过应用程序瘦身来减小,您可以在https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html阅读有关内容. 无论如何,您可能希望执行临时导出以查看应用程序的每个细化变体的大小。
回答by Nuray Altin
Embedded Bitcode is the reason.
嵌入式位码是原因。
Assuming you don't want to disable ENABLE_BITCODE, you can strip the debug symbols.
假设您不想禁用 ENABLE_BITCODE,您可以去除调试符号。
See http://oguzbastemur.blogspot.com/2015/09/xcode-7-and-increaded-binary-size.htmlas stripping debug symbols away before embedding bitcode is one of the options you can do.
请参阅http://oguzbastemur.blogspot.com/2015/09/xcode-7-and-increaded-binary-size.html,因为在嵌入位码之前剥离调试符号是您可以执行的选项之一。
回答by Stefan Arentz
We also had this problem with Swift 1.2. See How to prevent SwiftSupport libraries to be included twicefor my original question about this same issue.
我们在 Swift 1.2 中也遇到了这个问题。对于我关于同一问题的原始问题,请参阅如何防止 SwiftSupport 库被包含两次。
I am pretty sure this is a toolchain issue.
我很确定这是一个工具链问题。