What roles do ProGuard rules and R8 play in Android release builds?
Instruction: Explain shrinking, optimization and obfuscation, the relationship between ProGuard-style rules and R8, and how you validate an optimized release.
Updated
Official answer
ProGuard is associated with shrinking, optimization and name obfuscation in Java/Android tooling. In current Android Gradle Plugin builds, R8 normally performs the app's code optimization; it accepts ProGuard-style keep rules. A file named proguard-rules.pro does not mean the standalone ProGuard engine is running.
Shrinking removes code determined to be unused; optimization can simplify supported code paths; obfuscation renames eligible symbols. Smaller code can reduce package size, but removing unreachable code does not automatically mean the running app performs less work. Measure startup, memory and relevant paths rather than promise a speedup.
Enable optimization for the intended release variant using the configuration supported by that AGP version. Preserve entry points that static analysis cannot infer, such as required reflective access, serialization contracts or JNI lookups, using narrow tested rules and library consumer rules. A broad keep-everything rule may conceal the issue while eliminating useful optimization.
Exercise the actual optimized release build, including reflection and background entry points. Preserve the exact build's mapping output so obfuscated crashes can be retraced; a mapping from another build is not interchangeable.
Obfuscation can make inspection harder but cannot protect a client-embedded secret or replace server authorization. Test both functionality and artifact changes; do not equate successful compilation or reduced APK size with security certification.