ipa包分析 和 瘦身
ipa包太大,首先分析ipa 包各个部分的占比。查到的资料有如下
https://forums.xamarin.com/discussion/36858/how-to-understand-what-causes-large-ios-executable-size-and-reduce-it
https://stackoverflow.com/questions/23938500/decrease-ios-application-size-to-app-store
https://help.apple.com/xcode/mac/current/#/devbbdc5ce4f
苹果官网中说:
Inspecting an .ipa File
If the universal .ipa or any of the thinned .ipa files are larger than expected, the next step is to look at the thinned app bundle and see what files inside it are taking up the most space. The .ipa files are just a .zip archive that has a particular structure when unzipped.
Simply change the extension of an .ipa file to .zip, then open it with Finder to decompress it. Right-click on the unzipped .app bundle and choose "Show Package Contents" to see the resources inside. This can give you an idea of what is using the most space.
You can examine the compressed size of each item in the .ipa by opening Terminal and executing the following command:
使用这个函数在terminal中分析ipa包,会得到每个文件的压缩比,大小等等。
unzip -lv /path/to/your/thinned_app.ipa
分析我们的ipa包,得到的一个数据是:
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
0 Stored 0 0% 07-03-2018 09:52 00000000 Payload/
0 Stored 0 0% 07-03-2018 09:53 00000000 Payload/xxx.app/
3001 Defl:N 2989 0% 07-03-2018 09:23 c9f95b77 Payload/xxx.app/5scales@2x.png
448 Defl:N 359 20% 07-03-2018 09:23 58d4a00a Payload/xxx.app/5scales@3x.png
通过整理所有的记录,归结了4类占比:
ImageAssets 84M
Frameworks 36M
外部png 3.6M
代码 28M
其他 10M
首先想到的是压缩图片,使用tinyPng 压缩工具可对图片进行无损压缩,发现一个icon可以从12K 降到3k。
要求UI同事尽量使用8bit编码的图片,根据苹果官方文档
Use 8-bit Images Where Possible
Using an 8-bit PNG instead of a 32-bit PNG can decrease your image size by 4x,
采用开源项目LSUnusedResources对工程项目文件进行相关条件的筛查,排查出无用的资源和类文件(此排查方式基于项目代码及视图文件对类文件或者资源文件的调用次数进行排查),然后进行人为比对,确认无用或废弃的文件使用该工具进行物理删除。
LSUnusedResources