简体   繁体   中英

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.

I created a blank project with some pods and the build size goes to the 10MB and .app file is around 40MB.

I also notices that my .app file contains all my cocoapods frameworks (around 37MB) by viewing "Package content". 在此输入图像描述

My podfile having these pods

pod 'Alamofire', '~> 4.4'

pod 'SwiftyJSON'

pod 'IQKeyboardManagerSwift'

pod 'ActionSheetPicker-3.0'

pod 'Kingfisher'

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) ?
  2. How can we reduce the size of build by using cocoapods with Swift

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. 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.

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. I've seen apps that upload as 120MB or so to iTunesConnect and then the final download to the user is 20 to 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. 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). When using frameworks nothing is optimized out, but this is not happening due to Cocoapods. You can use frameworks without Cocoapods, and you should get exactly the same results regarding size.

Edit 2: It looks like swift 5 might achieve ABI stability! We might be able to choose swift for apps that need to be as small as possible now with it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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