Dev

ProGuard & R8 Rule Generator

Tick the libraries your app uses and copy production-ready keep rules. No signup, no server, everything runs in your browser.

  • Runs locally
  • No upload
  • Works offline

ProGuard / R8 rules

Keep rules for classes and members

Select rules to include

Generated rules

Rules are generated locally in your browser. Nothing is uploaded.

About this tool

This generator produces well-tested ProGuard and R8 keep rules for the most commonly used Android libraries. Tick a checkbox and the rules appear immediately in the output box. You can also type a fully-qualified class name to append a simple -keep class ... { *; } rule for any class you need to protect.

The output is plain text you can paste directly into your proguard-rules.pro file. Each block includes a comment so you know what it does when you revisit it later.

How to use

  1. Tick every library your app uses from the checkbox list.
  2. If you have a data class you want fully preserved, type its package path in the custom-class field.
  3. Click Copy rules and paste the text into app/proguard-rules.pro.
  4. Build a release APK or AAB and confirm no runtime crashes from missing members.

Tips

  • Run ./gradlew assembleRelease with -Pandroid.enableR8=true to see exactly what R8 removes.
  • The mapping.txt file in build/outputs/mapping/release/ lets you decode obfuscated stack traces.
  • For library modules, use consumer-rules.pro so consumers inherit your rules automatically.
  • Always test the release build on a real device, not just debug builds.

About ProGuard and R8 for Android

When you build a release APK or Android App Bundle, the Android Gradle Plugin runs a code shrinker. Before Android Gradle Plugin 3.4, that shrinker was ProGuard. Since then, R8 is the default. R8 reads the same rule file syntax as ProGuard, so all existing proguard-rules.pro files continue to work without changes.

What does R8 actually do?

R8 traces the reachable code starting from your application entry points and removes everything it cannot reach. It also renames classes, methods, and fields to short names to reduce the DEX size. That process breaks any code that locates classes or members by name at runtime, which is exactly what reflection-heavy libraries like Gson and Retrofit do.

Why keep rules matter

A -keep rule tells R8 to leave a class or member exactly as-is. A -keepclassmembers rule protects members without preventing the class itself from being renamed. The tool above uses the correct directive for each library. For example, Gson fields are protected with -keepclassmembers,allowobfuscation so the class can still be renamed, but the annotated fields survive.

Enums and Parcelable

Enums lose their values() and valueOf() methods if R8 decides they are not called directly. Many switch statements and serialization libraries call these methods via reflection, so the enum keep rule is a common source of silent bugs in release builds. Parcelable requires the CREATOR static field; without it, Bundle.getParcelable() throws a BadParcelableException at runtime.

Frequently asked questions

What is the difference between ProGuard and R8?

R8 is Google's replacement for ProGuard and is the default in Android Gradle Plugin 3.4 and above. It combines shrinking, obfuscation, and optimization in one pass and is generally faster than ProGuard. Both tools read the same rule file syntax.

Do I need keep rules if I am not using obfuscation?

If you disable minification entirely (setting minifyEnabled false), you do not need keep rules. However, if you enable shrinking even without obfuscation, R8 may still remove classes or members that it cannot statically prove are used. Keep rules protect those members.

Where do I put the rules in my project?

Add the rules to your module's proguard-rules.pro file. In your build.gradle, reference it with the proguardFiles directive. For library modules, use consumer-rules.pro instead so the rules are automatically applied to any app that depends on the library.

Will these rules increase my APK size?

Keep rules prevent R8 from removing or renaming the targeted code, which means slightly more bytes in the final APK compared to a fully-optimized build without keep rules. In practice the difference is negligible for library-level rules. The alternative, a crash at runtime, is far worse.