apk slimming

Use Proguard

Proguard is a very powerful tool that can help you confuse the code in the code compile time optimization and compression. It has a designed to reduce the apk file size feature called tree-shaking. Proguard will traverse all of your code and find out useless code. All of these unreachable (or no) code will be cleared out before the final of the apk file. Proguard also rename your class attributes, classes and interfaces, and then the entire code to keep the lightweight level as possible.

Maybe now you'll think Proguard is a very effective tool. But great power also comes great responsibility. Many developers now believe that Proguard little people do not worry, because it will depend heavily reflection. Which class or attribute needs to be processed or can not deal with every developer to configure Proguard.

Widely used Lint

Proguard Java code will only work, then the file to which resources? For example, a picture  my_image in a res/drawable folder, not used, Proguard will remove out  R references to class, but also still images folder.

Lint is a static code analyzer, you simply by calling  ./gradlew lintthis command it will simply help you to check all useless resource file. It will provide a detailed list of resource files after completion of detection and useless resources are listed under: "UnusedResources Unused resources" area. As long as you do not ask them to unwanted resources through reflection, you can safely remove these files.

Lint will analyze the resource file (such as  /res a folder under the file), but will skip the assets file (  /assets folder under the file). In fact assets files can be accessed directly through their file name, without reference or references to XML by Java. Therefore, Lint can not determine whether a file is useful asset in the project. It all depends on the developer of this file maintains a folder. If you are not using an asset file, then you can remove the file directly.

The main writing style or their own code, and reuse of methods -

Guess you like

Origin blog.csdn.net/a1033479126/article/details/56277635