Android ProGuard & R8 Rules Generator
Generate battle-tested proguard-rules.pro files for modern Android apps. Select your tech stack (Retrofit, Gson, Kotlinx Serialization, Room, Firebase, Hilt, Compose), preserve custom DTO models, and diagnose R8 release build crashes.
100% client-side · Private by design · No account required
Specify your app’s model package wildcard so R8 won’t obfuscate JSON response fields or strip no-arg constructors:
Include Baseline Android RulesKeeps line numbers for Play Console crash logs, JNI native methods, Parcelable CREATORs, & View XML constructors.
Select Your Tech Stack (6 Selected)
|
app/proguard-rules.pro
# ======================================================================
# Generated by CloseTesting.in Android ProGuard & R8 Rule Generator
# Date: 2026-10-21
# Drop this inside: app/proguard-rules.pro
# ======================================================================
# ======================================================================
# Standard Baseline ProGuard / R8 Rules for Modern Android
# ======================================================================
# Preserve line numbers and file names for deobfuscated crash logs in Play Console
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
# Preserve standard annotations and generic signatures
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
# Preserve native JNI C/C++ method bindings
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}
# Preserve custom View constructors for XML layout inflation
-keepclassmembers public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# Preserve Android Parcelable CREATOR instances
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
# Preserve Enum values() and valueOf() reflection
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# Custom Data Models / DTOs Preservation
-keepclassmembers class com.example.app.data.models.** {
<fields>;
<init>();
}
-keep class com.example.app.data.models.** { *; }
# ----------------------------------------------------------------------
# Google Gson
-keepattributes Signature
-keepattributes *Annotation*
-dontwarn sun.misc.**
-keep class com.google.gson.** { *; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# Retain @SerializedName annotations on model fields
-keepclassmembers class * {
@com.google.gson.annotations.SerializedName <fields>;
}
# ----------------------------------------------------------------------
# Square Retrofit 2
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepclassmembernames,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
# ----------------------------------------------------------------------
# Square OkHttp 3 & 4
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-keepclassmembers class okhttp3.internal.publicsuffix.PublicSuffixDatabase {
private static final byte[] *;
}
# ----------------------------------------------------------------------
# Firebase Crashlytics: Keep line numbers and source file names for stack trace mapping
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-dontwarn com.google.firebase.crashlytics.**
-keep class com.google.firebase.crashlytics.** { *; }
# ----------------------------------------------------------------------
# Google Play Billing Library
-keep class com.android.billingclient.api.** { *; }
-dontwarn com.android.billingclient.api.**
# ----------------------------------------------------------------------
# Kotlin Coroutines
-dontwarn kotlinx.coroutines.**
-keep class kotlinx.coroutines.android.AndroidDispatcherFactory { *; }
-keep class kotlinx.coroutines.CoroutineExceptionHandler { *; }
-keepclassmembers class kotlinx.coroutines.** {
volatile <fields>;
}
Gradle DSL Configuration (app/build.gradle.kts):
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}Frequently asked questions
- Where do I put the generated proguard-rules.pro file in Android Studio?
- Save the generated rules in your Android project at app/proguard-rules.pro. Then ensure your app/build.gradle.kts has isMinifyEnabled = true and proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro").
- Why does my Android app work fine in Debug but crash in Release?
- In Debug builds, R8 minification and code shrinking are disabled by default. In Release builds, R8 strips unused classes, renames variables, and drops reflection metadata. If your JSON models or DI classes are stripped, the app crashes with ClassNotFoundException or JsonSyntaxException.
- What is the difference between ProGuard and R8?
- ProGuard is a legacy third-party bytecode optimizer. Modern Android Studio builds use R8 by default, which combines desugaring, shrinking, obfuscating, and dexing into a single step. R8 understands standard ProGuard rule syntax while executing significantly faster and producing smaller APK/AAB sizes.
- How do I keep all my data models without disabling R8 minification?
- Instead of disabling minification globally, add a targeted keep rule for your models package, for example: -keepclassmembers class com.yourapp.data.models.** { <fields>; <init>(); } or annotate your data classes with @androidx.annotation.Keep.