IOS package slimming is actually just a few steps


This article continues to explain the slimming idea of IOS installation package.

  • Slimming guidelines

  • Conventional slimming program

  • Compress resources

  • Delete useless / duplicate resources

  • Delete useless code

  • Unconventional slimming scheme

  • Brain map reference

Slimming guidelines

The general guidelines are: compress resources, delete useless / duplicate resources, delete useless code, and optimize through compilation options.

Conventional slimming program

Compress resources

Resources in the project include pictures, strings, audio and video resources. Because there are many pictures in the project, resource compression generally starts with pictures. When adding pictures to the project, you need to usetinypngCompress the image or optim; In addition, you can notify the design, compress the cut image and upload it; Pictures that do not need to be embedded in the project can be downloaded dynamically.

  • Png, JPG, GIF can be replaced by webp

  • Animated pictures can be replaced with Lotties and apng

  • Thumbnails or emoticons can be replaced with iconfont

  • The larger picture can be replaced by SVG

Delete useless / duplicate resources

Delete useless resources. In the project, pictures are mainly deleted:

  • Use 2x and 3x pictures instead of 1x pictures.
  • You can use lsunusedresources to search for unused pictures and delete them. Note: the pictures searched by the software may still be used in the project. Before deleting, you need to search whether the pictures are used in the project, and then confirm whether they can be deleted.

Delete useless code

Delete useless classes and libraries: wbbladesformac can be used for analysis. Note: classes called through string will also be detected as useless classes.

Unconventional slimming scheme

1. Strip: remove unnecessary symbol information.

-Set strip linked product and strip swift symbols to yes, deployment postprocessing to no, and check strip swift symbols when publishing code.

  • Set the strip debug symbols during copy and symbols hidden by default to yes under release

  • Set dead code stripping to yes

  • For dynamic libraries, availableStrip - x [dynamic library path]Remove unnecessary symbol information

2. Make strings read only is set to yes.

3. Link time optimization (LTO) release is set to incremental. Wwdc2016 introduces that methods and codes that are not called will be removed during compilation to optimize the running efficiency of the program.

4. Enable bitcode

5. Remove exception support. You can’t use @ try @ catch. The package is only reduced by 0.1M, and the effect is not significant.

Set enable C + + exceptions and enable Objective-C exceptions to no, and add – fno exceptions to other C flags

6. Do not generate debug symbols: dsym cannot be generated, and the effect is very significant.

The generate debug symbols option release is set to No

Brain map reference

IOS package slimming is actually just a few steps

App package slimming

Recommended Today

Use of NFC developed by IOS

1、 Understanding NFCIn fact, the official documents on the use of NFC in IOS development have been very detailed. First go to the official documents:Document address: enabled devices:1. The mobile phone on IOS 11 only supports the function of reading, and you can read labels through the NFC function of the mobile phone2. The system […]