简体   繁体   English

使用Swift 3和pod进行iOS构建

[英]iOS build size with Swift 3 and pods

I just noticed cocoapods with Swift increases build size, however when I use same libraries manually then build size is normal. 我刚刚注意到使用Swift的cocoapods增加了构建大小,但是当我手动使用相同的库时,构建大小是正常的。

I created a blank project with some pods and the build size goes to the 10MB and .app file is around 40MB. 我创建了一个带有一些pod的空白项目,构建大小达到10MB,而.app文件大约为40MB。

I also notices that my .app file contains all my cocoapods frameworks (around 37MB) by viewing "Package content". 我还注意到我的.app文件通过查看“包内容”包含我所有的cocoapods框架(大约37MB)。 在此输入图像描述

My podfile having these pods 我的podfile有这些pod

pod 'Alamofire', '~> 4.4' pod'Alamofire','〜> 4.4'

pod 'SwiftyJSON' pod'SwiftyJSON'

pod 'IQKeyboardManagerSwift' pod'IQKeyboardManagerSwift'

pod 'ActionSheetPicker-3.0' pod'ActionSheetPicker-3.0'

pod 'Kingfisher' pod'Ginfisher'

pod 'JKNotificationPanel' pod'JKNotificationPanel'

My questions are 我的问题是

  1. why my .app file contains all framework, I guess it happens only with Swift and cocoapod (Correct me if I am wrong) ? 为什么我的.app文件包含所有框架,我想它只发生在Swift和cocoapod(纠正我,如果我错了)?
  2. How can we reduce the size of build by using cocoapods with Swift 我们如何通过使用Swift的cocoapods来减少构建的大小

Thanks in advance 提前致谢

If you use the libraries as static libraries, the linker can exclude the parts of them that you don't use from the build. 如果将库用作静态库,则链接器可以从构建中排除不使用它们的部分。 The same is not true for frameworks. 框架也是如此。 So if you just made an app with those libraries and didn't use them, they won't be included at all, so it's not a fair comparison. 因此,如果您刚刚使用这些库制作应用程序但未使用它们,则根本不会包含它们,因此这不是一个公平的比较。

When you ask why your app contains all frameworks I assume you mean the ones for the swift runtime and not the dependencies you explicitly asked for in cocoapods. 当你问为什么你的应用程序包含所有框架时,我认为你的意思是swift运行时的那些,而不是你在cocoapods中明确要求的依赖关系。 All swift apps have the runtime bundled into them, at least until the runtime becomes stable enough (changes very often nowadays), and then the phone OS will contain a few versions of it and we won't have to include it in the app. 所有swift应用程序都捆绑了运行时,至少在运行时变得足够稳定(现在经常变化)之前,然后手机操作系统将包含它的几个版本,我们不必将它包含在应用程序中。

Also, don't get terrified by the app size. 此外,不要被应用程序大小吓坏。 The actual size of the app the user downloads is much smaller. 用户下载的应用程序的实际大小要小得多。 You can see it in iTunesConnect's activity tab and then picking your build, once you've uploaded it there obviously. 您可以在iTunesConnect的活动选项卡中看到它,然后选择您的构建,一旦您将其上传到那里。 I've seen apps that upload as 120MB or so to iTunesConnect and then the final download to the user is 20 to 30MB. 我已经看到上传为120MB左右的应用程序到iTunesConnect,然后最终下载到用户的是20到30MB。

Edit after getting more info: You said you are comparing dragging the sources of libraries into your project vs cocoapods, and there's a clear difference here: if you add the source files of the library it's not the same as adding the compiled framework for the library. 获得更多信息后进行编辑:你说你正在比较将库的源代码拖到你的项目和cocoapods中,这里有一个明显的区别:如果添加库的源文件,它与为库添加编译框架不同。 If you add the sources, a lot of the unused stuff will be optimized out, thus affecting the size. 如果添加源,很多未使用的东西将被优化掉,从而影响大小。 Example of this is when a library includes a category that the library itself is not using. 例如,库包含库本身未使用的类别。 Unless some linker flags are used, the category is optimized out and it doesn't work on the app using the library (you can search for all_load if you want more info). 除非使用了某些链接器标志,否则该类别已经过优化,并且在使用该库的应用程序上无效(如果您想要更多信息,可以搜索all_load)。 When using frameworks nothing is optimized out, but this is not happening due to Cocoapods. 当使用框架时,没有任何优化,但由于Cocoapods,这不会发生。 You can use frameworks without Cocoapods, and you should get exactly the same results regarding size. 您可以使用没有Cocoapods的框架,并且您应该获得与大小完全相同的结果。

Edit 2: It looks like swift 5 might achieve ABI stability! 编辑2:看起来swift 5可能达到ABI稳定性! We might be able to choose swift for apps that need to be as small as possible now with it! 我们或许能够为需要尽可能小的应用程序选择swift吧!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM