ToolFount.Com Tools for everyday work

Android ProGuard Rules Keep Class Generator

Enter fully qualified class path or package prefix.
Copy to proguard-rules.pro
Syntax Status
✓ Valid ProGuard Rule

Secure Android Builds with an Android ProGuard Rules Keep Class Generator

Use our free tool, the android proguard rules keep class generator, to instantly build valid ProGuard and R8 rules (-keep class, annotations) for obfuscation and code shrinking in Android apps. When preparing an Android application for release on the Google Play Store, optimizing APK/AAB size and safeguarding source code against reverse engineering are critical steps. Android projects rely on ProGuard or the newer R8 compiler to shrink, optimize, and obfuscate bytecode by renaming classes, fields, and methods to short, unreadable characters.

However, over-aggressive obfuscation often breaks runtime reflection, serialization libraries (like Gson, Moshi, or kotlinx.serialization), and dependency injection frameworks (like Dagger or Hilt). If a data model class name is obfuscated, JSON deserialization fails silently or throws runtime exceptions. Developers must write explicit -keep configuration rules in their proguard-rules.pro file to protect specific classes from being renamed or removed. Our generator automates this process, eliminating syntax mistakes.

Understanding ProGuard and R8 Keep Directives

ProGuard and R8 rule files use specific syntax patterns to control how the compiler handles code blocks. Knowing how these directives function is vital for maintaining robust Android applications:

• -keep class: Ensures that the specified class name and public structure are preserved during code shrinking and obfuscation passes.

• Member Wildcards ({ *; }): Preserving a class name is often insufficient if its internal fields are renamed. Adding member blocks ensures variables, getters, setters, and constructors remain intact for reflection mapping.

• -keepattributes: Critical for preserving runtime metadata attributes such as Signature, EnclosingMethod, and RuntimeVisibleAnnotations, which annotation processors rely heavily upon.

Why Automate ProGuard Rule Generation?

Manually constructing ProGuard rules for dozens of API response models and database entities leads to cluttered configuration files and high human error rates. By leveraging the android proguard rules keep class generator, Android engineers can quickly generate precise keep rules on the fly, preventing release-day obfuscation bugs and ensuring stable production deployments.

Frequently Asked Questions (FAQ)

What is the difference between ProGuard and R8?

R8 is the default code shrinking and compilation tool integrated into Android Studio, replacing ProGuard. R8 uses the same ProGuard rule syntax, meaning existing rules like -keep class remain fully compatible.

Why do serialization libraries break without keep rules?

Libraries like Gson or Moshi use Java reflection to map JSON property names directly to matching variable names in data classes. If R8 renames those variables to single letters during obfuscation, reflection mapping fails.

Can I use wildcards for entire packages?

Yes. You can target entire directory structures using wildcards, such as -keep class com.example.model.** { *; }, which preserves every class contained within that model sub-package.

Where should I place the generated ProGuard rules?

Copy the generated snippet and paste it directly into the proguard-rules.pro file located in the app/ module directory of your Android Studio project structure.