R8, Shrinking & App Size
BUILD & TOOLING › Gradle
Shrinking, obfuscating, and optimizing apps with R8 and cutting download size with bundles.
This topic tests whether you can configure R8 correctly for a release build without crashing reflection-based code, and explain how Android App Bundles shrink real download size. Interviewers probe the difference between code shrinking, obfuscation, and optimization, why libraries like Gson need keep rules, and how you deobfuscate a production stack trace with mapping.txt. It is a favourite because misconfigured R8 is a classic source of release-only crashes.
What this covers
- Enabling R8 for release builds: minifyEnabled, shrinkResources, and proguard-android-optimize.txt, plus the dependency between code and resource shrinking
- The four jobs R8 performs in one pass: code shrinking (tree-shaking), obfuscation, optimization (inlining, class merging), and resource shrinking
- Writing keep rules for reflection: Hilt, Moshi codegen, and kotlinx.serialization ship consumer rules, while Gson model classes usually need manual -keep
- Reading mapping.txt to deobfuscate release stack traces via the retrace tool or Play Console upload
- Reducing download size with Android App Bundles and Play-generated per-device splits (density, ABI, language)
- Dynamic feature modules / Play Feature Delivery and asset-level wins like WebP, vector drawables, and @IntDef over enums
Study this topic
- R8, Shrinking & App Size explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- R8, Shrinking & App Size interview questions and answers