OC,Swift混编,Bitcode,cocoapod对ipa大小的影响

直接上结论

(结论针对本公司的工程而言,项目不同数据会有所不同):

  • OC 和swift 混编会让iPA 的包增大20M,即使你只有几个swift 文件,每一个swift文件代码都不多都可能增加20M
  • bitcode 会让ipa 包增加1.5M左右
  • cocoapod 的设置Objc打开会增加ipa的大小,几M左右,而且这个Objc 是最好要打开的
  • 文中还使用了RAC ,RAC对ipa的大小影响还没测试,有知道的欢迎给我留言

1) oc和swift 混编,bitcode 勾选上,ipa 文件大小49.8M

49.8M有点大 ,30M的时候老板就想更小点,50M老板估计不好接受

Snip20160809_11.png
Snip20160809_8.png

2) oc和swift 混编,bitcode 未选上,ipa 文件大小48.4M,比上面减少了1.4M

Snip20160809_9.png

3) 删除项目中的swift 文件,改为纯OC,ipa为29.7M,减少20M啊

Snip20160809_10.png

4) cocoapod中设置Objc 会让ipa 增大

cocoapod这么好用的工具,增大ipa 还是得用的.cocoapod 会让ipa 增大的,我没测试,详情见这位老外的问答.
问题:CocoasPod很好,但是-ObjC 在项目中会让所有的对象文件编译到二进制文件中,一个空的工程使用pod AFNetworking和"ObjC"打开,ipa的大小是7M.google map 需要ObjC 打开,这样导致ipa 17M ,所以这个老外想知道, Google Map SDK 的ObjC 打开,AFNetworking 的ObjC 关闭去减少ipa 的大小?
答案:别人的答案没说怎么办,只是说cocoapod 这么做是为了程序更好的编译.


CocoasPod is good, But sometimes it's not.Why? Because there is a flag call "-ObjC" in your project.It will pull ALL OBJECT FILES into your resulting binary.
For example, an empty project with "pod 'AFNetworking'" and the flag "-ObjC" is on, that will cause the binary will be 7MB. 7MB for an empty project, that's suck.
Some frameworks like Google Map SDK need the flag "-ObjC" is on.So, if your project with "AFNetworking pod" and "Google Map SDK", it will cause the binary will be 17MB.
So my question is:How can I turn off the "-ObjC" flag for special Library?For example, just keep the "-ObjC" for Google Map SDK, but turn it off on AFNetworking.
In general, adding a static library to your project in Objective-C will pull ALL OBJECT FILES into your resulting binary because cocoa pods installation adds -ObjC flag to your linker settings, and as stated in linker manual:
-ObjC Loads all members of static archive libraries that implement an Objective-C class or category.

This flag included to solve problem with linking categories, because by default linker will not include object files containing only categories into resulting binary.

文中的打包出的ipa大小都包含了RAC 和cocoapad.RAC对ipa的大小影响还没测试,估计在7M以内,

  • 最后的结论见文章开头,有不同的意见欢迎留言

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 希望,奢望。眼前,遥远。分过,合过。 失望,绝望。梦醒,结束。恨过,痛过。 祈求,奢求。承诺,谎言。哭过,伤过。 ...
    一朵愁云阅读 163评论 0 0
  • 文/子子穆 前段时间,鱼日姑娘在我们好友群里宣布:我跟戚先生领证啦!一下子群里就炸开了锅,搞得我们这些单身狗们一脸...
    子子穆阅读 5,963评论 13 25
  • “黑社会”。是我老婆对以前一个邻居,给起的代号。 其实,这邻居,并不是真的黑社会成员。只是,这个人长的有点像。肚子...
    时间刀客阅读 409评论 0 0