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

来源:互联网 发布:服装软件哪个好 编辑:程序博客网 时间:2024/06/11 16:46

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

  • 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以内,

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