Android package volume is still more annoying, users see such a large APK or each time the update of the time to spend a huge amount of traffic to update you want to uninstall your APK, here is a record of the APK volume optimization scheme

Analysis tools

First, we can use the Analyze APK of Android Studio to detect the Analyze APK. We can use the Analyze APK to see exactly where the APK takes up space.

Use a set of resource files

Normally, when doing some adaptation, let the UI cut images of different sizes for adaptation, but we can make the UI cut a set of image resources and put them in XHDPI. Our project has always been handled this way, and it will feel the same on different mobile phones with different resolutions

Turn on code obfuscation

I can reduce the package size by turning on code obfuscations and then configuring some resource compression. My existing project is 44M, turn on obfuscations and it will go to 39M

buildTypes {
    release {
  	  minifyEnabled true}}Copy the code

Remove unwanted resources

ShrinkResources reduces package size by enabling shrinkResources to replace resources that don’t have any parent class calls with smaller ones

buildTypes {
        release {
            shrinkResources true}}Copy the code

Clean up useless resources

Remove Unused Resources with The Android Studio app to Remove shrinkResources completely. Remove shrinkResources with the Android Studio app to Remove shrinkResources

Careful! Some reflection or string concatenation methods will also be removed

Delete unnecessary languages

Set up language support with the resConfigs configuration. If there are no foreign requirements, we just need a Chinese language

defaultConfig {
        resConfigs "zh"
    }
Copy the code

Image compression

Use tools to compress resource images, or use some JPEG, WebP images,

So files are armable only

So file we can use armable, armable-x86 two kinds, basically adapt, if there is a specific need to add the other kinds

Use the wechat resource compression and packaging tool

Using the open source tool wechat AndResGuard to compress resources, it will confuse the file names of resources

Compile using provided

When we integrate some third party, there may be A problem, in different parts of the customization development, such as A region need video conference function, and don’t other region, then the other areas we should not video conference in this function, but if you don’t call in, jump code etc and complains, We can rely on this provided to ensure that the compile passes

Create an argument isMetting=true in gradle. properties

Build. Gradle then determines which parameters to rely on separately

	if(isMeeting.toBoolean()){
        implementation project(':mettinglibrary')}else{
        provided project(':mettinglibrary')}Copy the code

Use shaP background

If you can use SHAP, don’t let the artist give you resources

Avoid duplicate libraries

To avoid duplicate libraries, for example, I reference two three-level linked libraries for rapid development, pure waste of space, take a good look at each reference in the library’s real use, where to use, whether it is redundant

Remove third-party libraries and redundant code

Will produce some useless in the rapid development of the code, as far as possible to clean up his, sometimes to a demand, waiting for you after ready, he said no, and then write a lot of code to the abandoned, sometimes you really do not know whether he said don’t really don’t, a short time, and were afraid to delete, so we can delete a dead code two months on a regular basis

Support for plug-ins

Is to isolate the APP business, the plug-in, the code simple, don’t pack to pack, can be said to be the most efficient way to reduce the package size, if he doesn’t care about your other resources compression, needed to download, but domestic pluggable risk will have a fit, and go to Google now also does not support this

Refer to the blog: blog.csdn.net/u012124438/…

Thanks to big guy’s blog, let me learn a lot, I wrote above is I have tested, or is using the program, true and effective.