AndroidStudio new project apk package slimming

Recently, I want to start a new project, build a new project, and run it to compile a package. I don’t know if I don’t see it. I was shocked when I saw it. A new project, I didn’t do anything, and the compiled package was 2.8MB.

As a tech dev, I feel deeply hurt, reminds me of the strong dog vs weak dog memes

I can't bear it, I must lose weight for it!

First look at the components of the package and drag it into AndroidStudio

The dex file is relatively large, so let's optimize it from dex first, and decompile the dex with dex2jar

 

It can be seen that, except for the three classes in my own directory, there are only a few classes under the v4 package, which does not take up much space. Since the targetSDK version is relatively high, there is no way to get rid of the AndroidX reference, and other things can actually be optimized, because I don't have to use it at present.

delete material

Delete ConstraintLayout in layout

Remove the reference in build.gradle

Delete the related Theme reference of the material in the style file

Pack again, the package size becomes 1.3MB

It can be seen that the dex file, res and resource.arcs have been significantly reduced 

 In fact, you can further reduce the package size by obfuscation

After adding the obfuscation, the volume of the apk package becomes 853KB, well, it feels within the acceptable range

 

 

Guess you like

Origin blog.csdn.net/guo_zhen_qian/article/details/125081263