Mobile Development 17 min read

Baidu App APK Size Optimization: Fundamentals, Tools, and Practices

The article explains why reducing APK size improves download conversion and performance, then details a systematic, divide‑and‑conquer approach for Baidu App that trims Dex, resources, native libraries and ZIP overhead using tools such as R8, AndResGuard, ByteX, Booster and AGP, achieving a reduction from roughly 123 MB to 115 MB with up to 6 MB saved per batch and outlining plans to open‑source the utilities.

Baidu Geek Talk
Baidu Geek Talk
Baidu Geek Talk
Baidu App APK Size Optimization: Fundamentals, Tools, and Practices

This article introduces the importance of APK size for download conversion, installation time, runtime memory and disk usage, citing Google Play data that a 10 MB reduction can increase conversion by about 1.5%.

Basic Idea

The optimization focuses on the intrinsic size of the APK, especially Dex, resources, and native libraries, rather than business‑related code. It follows a "divide‑and‑conquer" and "sustainable optimization" approach, building long‑term mechanisms that continue to benefit future builds.

APK Structure Analysis

The APK is a ZIP archive containing classes.dex , resources.arsc , res/ , lib/ , assets/ , META-INF/ and AndroidManifest.xml . Understanding the ZIP layout (local file headers, central directory, end of central directory) is essential for size reduction.

Existing Optimization Tools

Various tools are used:

ProGuard – class shrinking, obfuscation and byte‑code optimization (pre‑AGP 3.3).

R8 – integrates D8 and code shrinking, recommended after AGP 3.3.

AndResGuard – resource name obfuscation and compression.

ByteX – Java bytecode instrumentation (R‑class inlining, debug‑info removal, access‑method inlining).

Booster – Didi’s framework for resource compression, .ap_ compression, redundant‑resource removal, R‑class and DataBinding inlining.

AGP (Android Gradle Plugin) – provides built‑in tasks such as OptimizeResources , StripSymbols , ShrinkResources , PackageOptions , and Splits .

Dex Optimization

Two categories of Dex optimizations are applied: compile‑time (using bytecode tools like ASM) and post‑packaging (using Dex tools such as Titan‑Dex). Techniques include R‑class inlining, line‑number table removal, and annotation stripping.

Resource Optimization

Optimizations target resources.arsc and raw files in res/ and assets/ . Strategies include resource name/ path deduplication, path hash‑based shortening, removal of file extensions, configuration pruning, PNG compression (TinyPNG, ImageOptim), and precise resource shrinking introduced in AGP 7.1.

ZIP Optimization

Compression algorithms (7z, Zopfli) are employed while ensuring resources.arsc remains uncompressed for mmap‑based loading. File‑path shortening in META‑INF, local headers and central directory also yields size gains.

Other Optimizations

Night‑mode resources are merged into a single APK with unified IDs, ProGuard/R8 rule hygiene is enforced, and a continuous volume‑monitoring pipeline detects abnormal growth.

Results

From August 2021 to February 2022, multiple optimization batches reduced the Baidu App APK from ~123 MB to ~115 MB, achieving up to 6 MB savings per batch. Detailed before/after figures are provided in a table.

Conclusion

The article outlines the systematic approach to APK size reduction, the tools used, and the measurable impact, with plans to open‑source the generic optimization utilities.

AndroidR8DexProGuardAPK optimizationresource-compression
Baidu Geek Talk
Written by

Baidu Geek Talk

Follow us to discover more Baidu tech insights.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.