Enhance Proguard rules to preserve enum methods and improve annotation retention

This commit is contained in:
2025-10-01 02:35:59 +08:00
parent 81d9b31f6c
commit a2e1791199

View File

@@ -62,9 +62,23 @@ public data class ProguardConfig(
if (!dontKeepClassNames)
appendLine("-keepnames class $targetName")
// Keep the `JsonClass` annotation on the target class, R8 will shrink it away otherwise.
// Keep the `JsonClass` annotation on the target class, R8 will strip it away otherwise.
appendLine("-keep${if (dontKeepClassNames) ",allowobfuscation" else ""} @com.squareup.moshi.JsonClass class *")
//
// -keepclassmembers enum * {
// public static **[] values();
// public static ** valueOf(java.lang.String);
// public static <fields>;
// }
//
// Keep the enum values method, R8 will strip it away otherwise.
appendLine("-keepclassmembers enum * {")
appendLine(" public static **[] values();")
appendLine(" public static ** valueOf(java.lang.String);")
appendLine(" public static <fields>;")
appendLine("}")
appendLine("-if class $targetName")
appendLine("-${if (dontKeepClassNames) "keepclassmembers" else "keep"} class $adapterCanonicalName {")
// Keep the constructor for Moshi's reflective lookup