iOS ipa reduce the size of

First, iQIYI

IQIYI path optimization of mobile applications: how to make the collapse less than two thousandths

  1. iOS8 limited to 60MB of App segment of text;
  2. More than 200MB of App requires WIFI connection to download (before is 150MB)
  3. Excessive lead to a slow start, long rebase / binding time
  4. Remove the App Store introduction, screenshots, many users are concerned about the size of the App, especially the use of space for the 8G, 16G users

Optimization of the size of the installation package, comprising two main blocks: optimization and optimization of binary size of the resource size.

The size of the resource optimization relatively simple, mainly includes the following aspects:

  1. Resource Compression
  2. Unused, delete duplicate resources
  3. Resources on the cloud

1.1 Resource Compression

Xcode compiler options, providing Compress PNG FilesandRemove Text MetaData From PNG Files

However, because PNG is lossless compression, image resources through Xcode after compression, it is still great.

PNG whether it be through "lossy" compression to reduce the size of it? The answer is yes. UI colleagues generally in FIG. 32 are images, corresponding to FIG. 32 + 24 Alpha FIG transparency, total can Showing 2 24 = 16,777,216 colors. Color-rich picture is good, but in general, image color range APP package is physically small, button or using the Figure 8 small map with the naked eye can not see any difference Figure 32.

So team uses pngquant for most 32-bit map has been processed, it will map into eight, and use Zopfli is compressed, so that the overall resources of PNG image is compressed by about 70%. Here we note that, due to the large number of color coverage gradient background, color map into eight large loss, the performance effect will be much worse, so these pictures to be handled with care.

1.2 is not used, delete duplicate resources

With the iterative version, some features may be off the assembly line, sometimes related resources are not deleted in time, some features due to different developers, it may be relatively common part of the picture will be repeated. This part of the resources will accumulate slowly over time, to detect and delete is necessary.

Whether pictures are used, it can be determined by matching the picture name string. Note that the case name stitched picture (such as beginners guide function, it is prone to the case of digital mosaic picture name), in the course of the pre-image resources, there are usually two or more pictures have the same prefix or suffix, you can the same parts thereof are extracted, as the basis for matching string.

Repeat resources situation will generally occur in some buttons or background images generated by the UI with a colleague, he was sent to developers of different functions. This determination may be generally the same part of the picture by picture or similar size (size in the range of 5%), screening for the same resolution, and then by comparing image magick compare tools, a great similarity can be extracted.

Last tools developers need to output a secondary confirmation, to ensure that the situation does not appear there accidentally deleted.


1.3 cloud resources

Cloud resources can effectively reduce the resources within the package, only to note that these resources because it is lazy load, it is more suitable for deep-level pages use. Picture logic can be packaged as tools, just call the front using a method which pictures to take specific local, which pictures go cloud strategies can be freely configured. In addition, another advantage of cloud resources can easily achieve dynamic skinning.


JS, expression libraries and other resources are available through a pre-packaged form download, and update policies to increase, so RN page, WebView, do not take up the expression library installation package size.

Optimized binary size is relatively difficult to remove part of the functionality using a Web page or RN, current research focuses on useless class, analyze and delete unwanted code.

Xcode can generate a Link Map file, the file consists of information about the path to the executable file, object file, symbol or the like. __Objc_classrefs indicates that the referenced file to the class, _objc_classname represent the class name in the App, by analyzing the difference between the two can be drawn from category unused, empathy, analysis __objc_selrefs and _objc_methname difference can be drawn unused method. However, due to the dynamic nature, the result will be a large number of false positives OC situation. So how do you reduce false positives it? Dead code may be analyzed by the accuracy of the code coverage case, to improve.

Xcode 设置中开启代码覆盖率后,编译时会生成 gcno 文件,程序运行时会产生 gcda 文件,通过 lcov 解析即可得到代码测试覆盖率。如果开发阶段开发人员的自测,以及全功能 case 跑完,都有一些类或方法没有被覆盖到,并且这些类或方法又跟 Link Map 文件分析的结果一致,那么这些类或方法会被标记为无用代码,由工具统一收集并指派给相关开发人员进行处理。

二、其他处理

  1. 配置编译选项 Generate Debug Symbols 设置为 NO;

  2. 舍弃架构,如:armv7,根据实际选择。

  3. 编译的版本必须是 release 版本,

  4. 查找内部使用到的第三方库,一方面可以进行删减代码,用不到的类,直接删除,还有第三方库中的图片资源统统删除掉,如果能够自己手写实现的,那费功夫自己写吧

  5. 图片

    • 压缩图片

      不重要的图片可适当采用 8bit png 图片

      矢量图:由计算机的算法产生的,可以无限放大或缩小,不会有任何损失,通常由矢量软件制作。

      位图:由一个一个的小色块组成,放大后会看到那些小色块,同一面积内小色块越多,分辨率就越高。

      矢量图优点:

      • 可以无限放大或缩小,不会影响图像素质;
      • 文件体积较小,编辑灵活

      缺点:

      • 表达的色彩层次不清,整体观感效果不如位图

      位图优点:

      • 能很细腻地表达图片的效果,图片表达效果非常好

      缺点:

      • 不能放太大,减少文件分辨率后会影响图片质量
      • 图片占据空间较大

      一些对图片要求高的用位图,如:照片。其他的尽量用矢量图,如:文字、表格、卡通图片等

    • 去掉无用的图片

      • 用代码绘制简单的纯色图片 用 Sketch 和 PaintCode 快速得到绘制代码。
      • 如果不需要使用透明,可以用 jpeg 代替 png。jpeg 减少了些效率但更加小。需权衡性能,大小。
      • 对 32 位的图片,尽可能的使用高压缩率,使用 PS 的“Save For Web”功能,可以有效的减小 JPEG 和 PNG 图片的尺寸。 默认情况下,在 build 时,PNG 图像就被 pngcrush 压缩。
  6. 音频

    压缩音频,尽可能使用 AAC 或者 MP3 格式,并且使用一个较低的码率。通常 44.1khz 的码率有点浪费,降低一定的码率也不会丢失多少音质。

  7. 视频

    视频也可以使用类似于音频的处理方法,音视频的压缩可以很大程度的压缩,但是要注意压缩的格式,是不是会增加编解码的负担,这要权衡考虑。

  8. Assets

    检查 bundle 中的无用文件,不要打包到 app 或者静态库中。可以点击文件,在右侧的 file inspector 里面的 target membership 中取消勾选;或者在 build phase 里面的 Copy Bundle Resources 中去掉。

    确定 dead code(代码被定义但从未被调用)被剥离,Build Settings 里 DEAD_CODE_STRIPPING = YES。去掉冗余的代码,即使一点冗余代码,编译后体积也是很可观的。

Guess you like

Origin www.cnblogs.com/dins/p/ios-suo-xiao-ipa-da-xiao.html