Skip to content

ProGuard and R8

Question

ProGuard

Short interview answer

ProGuard rules are now commonly consumed by R8, Android’s shrinker and optimizer. R8 can remove unused code, optimize code, and shorten identifiers; code reached through reflection needs explicit keep rules.

Detailed answer

Enable shrinking for release builds incrementally and verify affected flows. A reflective serializer may need a narrowly scoped keep rule:

-keep class com.example.api.dto.** { *; }

A rule that is too broad loses size benefits; a missing rule can break serialization, reflection, or native callbacks. Keep rules with the dependency or feature that requires them.

Sources