Everything works perfectly in debug mode, but the moment you build a release APK, it crashes with a cryptic error. Welcome to the world of R8 (formerly Proguard). It's designed to shrink your app, but it can accidentally shrink your important code too.

The Reflection Trap

R8 works by removing unused code. But it doesn't know code is "used" if it's called via reflection—which is exactly how libraries like GSON and Retrofit work. If R8 renames or removes your data models, parsing will fail silently.

Keep Rule # Prevent R8 from obfuscating your data models
-keep class com.avni.app.models.** { *; }

The Retain Strategy

Instead of manual rules for everything, I use the @Keep annotation. It's much simpler and less prone to errors when you move files around.

Keep Annotation @Keep
data class UserProfile(
val name: String
)

The Pro Rule

Never release an app without testing the Release build on a real device. Debug and Release are fundamentally different binaries. Catch the R8 issues before your users do!

Summary

Respect the shrinker. Use @Keep and custom rules to protect your reflections and your peace of mind.