Keep Rules in the Age of Kotlin

James Hamilton

Software Engineer


ProGuard has been the industry standard for obfuscating, shrinking and optimizing Java & Android apps for close to 20 years. ProGuard, and the compatible R8 shrinker, usually need some configuration since it's not always technically possible to determine which entities should be processed. The configuration for these tools is based on `-keep` rules that use a Java-like template syntax.

Now that Kotlin is the preferred language for Android development, using `-keep` rules can be tricky since the Kotlin code strays further from the Java-like template syntax. Kotlin also presents an additional problem: Kotlin-specific features are embedded in metadata stored as annotations to Java classes. This metadata must be kept and adapted appropriately when using reflection or Kotlin-specific features.

Key Takeaways:

1. We’ll show how to determine `-keep` rules for Kotlin apps & libraries through various examples with the help of the ProGuard Playground (
2. We’ll describe how ProGuard (and R8) can process Kotlin metadata to support Kotlin specific features.
3. We’ll also clear up any confusion about R8 replacing ProGuard as the new default shrinker for Android and what this means for ProGuard

I've been working as a software developer at Guardsquare working on ProGuard and DexGuard for 2 years.
Previously, I worked at CERN in Switzerland and before that earned a PhD in Computer Science, with a focus on code analysis, from the University of London.