Techniques for Reducing Android APK Size in Meituan App
To shrink Meituan’s Android APK, developers can optimize the ZIP layout, enable ProGuard/R8 dex shrinking, inline R fields, convert images to WebP or VectorDrawable, disable redundant PNG crunching, activate shrinkResources, limit packaged languages, obfuscate resources with tools like AndResGuard, and eliminate duplicate or unused assets.
As Meituan’s app rapidly adds new business logic, image resources, and third‑party SDKs, the APK size keeps growing, leading to higher CDN costs, lower installation success rates, and potential impact on user retention. This article shares a series of practical techniques for shrinking the APK.
APK Composition
An APK is a ZIP archive. By opening it with a ZIP tool you can see the main parts: compiled code (classes.dex), resources (res/), AndroidManifest.xml, resources.arsc, and various Java resources such as org/, src/, push_version, etc. Understanding these components is the first step to optimization.
Zip Format Optimization
Many files in the APK are stored uncompressed (Stored) because they are already compressed formats (e.g., .jpg, .png, .mp3). The AAPT source defines a list of extensions that are not compressed:
/* these formats are already compressed, or don't compress well */
static const char* kNoCompressExt[] = { ".jpg", ".jpeg", ".png", ".gif", ".wav", ".mp2", ".mp3", ".ogg", ".aac", ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet", ".rtttl", ".imy", ".xmf", ".mp4", ".m4a", ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2", ".amr", ".awb", ".wma", ".wmv", ".webm", ".mkv" };Changing the compression method for these files can reduce size, but must be done carefully.
Classes.dex Optimization
Maintain good coding habits, remove dead code, avoid unnecessary third‑party libraries.
Enable ProGuard (or R8) to shrink, obfuscate, and optimize bytecode. In build.gradle set minifyEnabled true and configure proguardFiles:
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}After ProGuard runs, mapping files show which classes have been removed, e.g., android.support.multidex.MultiDex.
R Field Optimization
Inlining R fields via bytecode manipulation (using Javassist or ASM) can reduce the number of R references and help avoid the 64K method limit.
Resource Optimization
Image Optimization : Choose the appropriate format—VectorDrawable for simple icons, WebP for most images, PNG for transparency‑required assets. Use tools such as pngcrush , pngquant , or zopflipng for PNG, and packJPG or guetzli for JPEG.
Disable AAPT’s automatic PNG crunching when you have already optimized images:
aaptOptions {
cruncherEnabled = false
}Resource Compression : Set shrinkResources true in build.gradle to replace unused resources with tiny placeholders. Example:
android {
...
buildTypes {
release {
shrinkResources true
}
}
}Note that values/ resources are not removed by the compressor; you may need to manually delete them.
Language Resource Optimization : Limit packaged languages via resConfigs:
android {
defaultConfig {
resConfigs "zh", "zh-rCN"
}
}resources.arsc Optimization
Enable resource obfuscation (e.g., using AndResGuard).
Remove duplicate resources by comparing CRC‑32 checksums and redirecting them to a single entry.
Delete unused resources identified by the resource‑usage analyzer.
Summary
The presented techniques—Zip format tweaks, dex shrinking, R field inlining, image format selection, resource compression, language filtering, and duplicate‑resource removal—can collectively reduce APK size significantly. Combining these with a disciplined development approach and selective feature removal yields the most effective size reduction.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Meituan Technology Team
Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
