Inside the Android app pack, the bulk is mainly three pieces

  • The dex file, or Java/Kotlin code, was more likely to be compressed, optimized, and obfuscated using Proguard, and there wasn’t much room to optimize after Proguard. Of course, you can use plug-in to dynamically deliver.
  • One is the SO library. If it is not the SO library developed by our company, there is basically no way to optimize the SO volume of the three-party library. Of course, you can still use the cloud dynamic delivery.
  • One is the resource picture, of course, still can picture server through glide from the cloud pull. Gradle plugin or tool is used to optimize the image resources.

1. Use the Remove Unused Resource of Lint

APK’s resources mainly include images and XML. Like redundant code, it may also leave behind many resources that are used in the old version but not in the new version, which is more likely in rapidly developing apps. You can right-click Refactor and click “Remove Unused Resource => Preview” to preview found Unused resources and click “Do Refactor” to Remove redundant resources. As shown below:

2. Detect duplicate resources

In project development, different names may often appear but they are actually the same picture or shape. At this time, it is very difficult and time-consuming to observe with naked eyes. For the uniqueness of files, we can distinguish whether they are the same resource through MD5.

3. Detect large images and upload them to the CDN picture server

Some of the larger images in the project don’t necessarily have to be local. Under normal circumstances, pictures above 100K need to be put into the picture server, so there are so many developers, there will always be careless will be put locally. If the size of the image is larger than a certain size, the exception can be thrown directly. This is a gradle plugin that detects the volume of images

4. Detect non-WEBP images

Webp format is a picture format launched by Google. Compared with PNG, it has been compressed in volume to some extent, with lossless WebP compression of nearly 30% and lossy WebP compression of nearly 80%. Due to the small screen of mobile phone, it is difficult to detect the difference by using lossy WebP to the naked eye. So using lossy WebP format, 100K is close to being compressed to a couple of 20k, and the effect is still very objective. Normal company UI provides images with webP, but some students may be careless to choose PNG. It is not practical to visually inspect the image format every iteration, so a plugin is still written to detect the presence of non-WebP images

The code address