APK Shrinking Practices for JD Finance Android App
This article details the systematic reduction of the JD Finance Android app's APK size from 117 MB to 74 MB between 2019 and 2022, covering background analysis, APK and SDK component breakdown, a series of optimization techniques—including image processing, resource inlining, compression tools, dynamic SO loading, and pluginization—plus governance, results, and future plans.
Background – The JD Finance Android app grew rapidly, exceeding 117 MB from 2019‑2022, which negatively impacted download conversion, installation time, and device storage. A dedicated slimming campaign started in September 2022 and reduced the package to 74 MB without removing business code.
APK Content Analysis – The APK is a ZIP archive containing classes.dex , resources.arsc , res/ , lib/ , assets/ , META-INF/ , and AndroidManifest.xml . Understanding each component’s size is essential for targeted reduction.
SDK Size Analysis – Using the internal Pandora tool, the sizes of third‑party SDKs were visualized, revealing that many SDKs (especially those with multiple native .so libraries) contributed heavily to the overall size.
ZIP Structure Analysis – The zipinfo -l --t --h test.apk > test.txt command lists each file’s original and compressed sizes, enabling per‑file size indexing and identification of compression opportunities.
Shrinking Practices
Image Optimization – Convert all images to WebP, apply multi‑DPI merging, and run Pngquant for lossy compression.
R‑file Inlining – Replace R.layout.xxx references with raw integer IDs (e.g., setContentView(2131427356); ) and then delete the generated R classes.
AndResGuard – Shorten resource names in resources.arsc to reduce the resource table size.
7‑zip Compression – Re‑package the unsigned APK with 7za a -tzip -mx9 target.zip extracted_dir , then store uncompressed files (e.g., native libraries) with -mx0 to avoid runtime decompression overhead.
CPU Architecture Configuration – Build only arm64‑v8a binaries via ndk { abiFilters "arm64-v8a" } .
resources.arsc Compression – Although compressing resources.arsc saves space, it can increase memory usage and start‑up time; therefore it is disabled for targetSdkVersion ≥ 30.
Internationalization – Remove unused language resources with defaultConfig { resConfigs "zh", "en" } .
shrinkResources & minifyEnabled – Enable both flags in build.gradle to delete unused resources and code.
Advanced Technical Solutions
Dynamic SO Loading – Download required .so libraries at runtime and inject them into the class loader using reflection (see code snippet below).
Pluginization – Split the monolithic APK into independent plugin modules that can be loaded on demand, allowing hot‑fixes and reducing the base package size.
System.load("{secure_path}/libxxx.so")
// Reflective injection of new native library paths
final Field pathListField = ShareReflectUtil.findField(classLoader, "pathList");
final Object dexPathList = pathListField.get(classLoader);
final Field nativeLibraryDirectories = ShareReflectUtil.findField(dexPathList, "nativeLibraryDirectories");
List
origLibDirs = (List
) nativeLibraryDirectories.get(dexPathList);
origLibDirs.add(0, new File(folder));
final Method makeElements = ShareReflectUtil.findMethod(dexPathList, "makePathElements", List.class);
Object[] elements = (Object[]) makeElements.invoke(dexPathList, origLibDirs);
final Field nativeLibraryPathElements = ShareReflectUtil.findField(dexPathList, "nativeLibraryPathElements");
nativeLibraryPathElements.set(dexPathList, elements);Business Optimization & Governance – Low‑UV business modules are evaluated for removal or pluginization. A control platform monitors package changes across builds, flags regressions, and enforces SDK size limits.
Results & Future Plans – After two quarters and five releases, the APK size stabilized at ~74 MB. Ongoing plans include automating the slimming pipeline, integrating the control platform with CI/CD, and periodic audits to prevent size regression.
References
Google Play: Shrinking APKs – link
ProGuard – link
R8 – link
AndResGuard – link
JD Tech
Official JD technology sharing platform. All the cutting‑edge JD tech, innovative insights, and open‑source solutions you’re looking for, all in one place.
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.