In past development, the resulting APK was often too large due to the images, music files, special font files used in the project, and the third package imported. Too large APK will be very bad for users’ experience, such as slow download and heavy traffic consumption. So developers need to compress their APK properly.

1. Remove additional language configurations when no internationalization is required

Configure resConfigs in defaultConfig in build.gradle of the project App Module to configure only the required language options.

2. Remove unnecessary SO architecture

Configure the NDK in defautlConfig in build.gradle of the project app Module. Configure only the required SO library. Armeabi-v7a, ARM64-V8A basically meet the requirements, if you need to use virtual machine testing can add x86

3. Use WebG instead of PNG or JPG

Webp is a lossy compression format developed by Google. This image format loses almost no quality compared to PNG or JPG, but the compressed image is much smaller than PNG or JPG.

4. Confuse the configuration

There’s code confusion and resource confusion

4.1 Code Confusion

Proguard can obfuscate and optimize code and reduce the size of dex files. After enabling proGuard, you need to configure proGuard-rules. pro file to retain classes that do not need to be obfuscated and classes of third-party packages. To enable obfuscation, set minifyEnable to true in the release of buildType in the project app Module. ProguardFiles is your obfuscation rule file.

4.3 Resource Confusion

For resource obfuscation, I used wechat AndResGuard, which makes the resource path shorter. Github address: github.com/shwenzhang/…

Configuration process: 1. Add it in build.gradle at the project level2. Add plug-ins to build.gralde in app ModuleAdd andResGuard to build.gradle in app Module. Note whiteList. Github contains a list of three libraries that need to be added. Note that if a project uses getIdentifier to find a Drawable or MiPmap resource, the resource name must be whitelisted.