### Gson ProGuard and R8 rules which are relevant for all users ### This file is automatically recognized by ProGuard and R8, see https://developer.android.com/build/shrink-code#configuration-files ### ### IMPORTANT: ### - These rules are additive; don't include anything here which is not specific to Gson (such as completely ### disabling obfuscation for all classes); the user would be unable to disable that then ### - These rules are not complete; users will most likely have to add additional rules for their specific ### classes, for example to disable obfuscation for certain fields or to keep no-args constructors ### # Keep generic signatures; needed for correct type resolution -keepattributes Signature # Keep Gson annotations # Note: Cannot perform finer selection here to only cover Gson annotations, see also https://stackoverflow.com/q/47515093 -keepattributes RuntimeVisibleAnnotations,AnnotationDefault ### The following rules are needed for R8 in "full mode" which only adheres to `-keepattribtues` if ### the corresponding class or field is matches by a `-keep` rule as well, see ### https://r8.googlesource.com/r8/+/refs/heads/main/compatibility-faq.md#r8-full-mode # Keep class TypeToken (respectively its generic signature) -keep class com.google.gson.reflect.TypeToken { *; } # Keep any (anonymous) classes extending TypeToken -keep,allowobfuscation class * extends com.google.gson.reflect.TypeToken # Keep classes with @JsonAdapter annotation -keep,allowobfuscation,allowoptimization @com.google.gson.annotations.JsonAdapter class * # Keep fields with @SerializedName annotation, but allow obfuscation of their names -keepclassmembers,allowobfuscation class * { @com.google.gson.annotations.SerializedName ; } # Keep fields with any other Gson annotation # Also allow obfuscation, assuming that users will additionally use @SerializedName or # other means to preserve the field names -keepclassmembers,allowobfuscation class * { @com.google.gson.annotations.Expose ; @com.google.gson.annotations.JsonAdapter ; @com.google.gson.annotations.Since ; @com.google.gson.annotations.Until ; } # Keep no-args constructor of classes which can be used with @JsonAdapter # By default their no-args constructor is invoked to create an adapter instance -keepclassmembers class * extends com.google.gson.TypeAdapter { (); } -keepclassmembers class * implements com.google.gson.TypeAdapterFactory { (); } -keepclassmembers class * implements com.google.gson.JsonSerializer { (); } -keepclassmembers class * implements com.google.gson.JsonDeserializer { (); } # If a class is used in some way by the application, and has fields annotated with @SerializedName # and a no-args constructor, keep those fields and the constructor # Based on https://issuetracker.google.com/issues/150189783#comment11 # See also https://github.com/google/gson/pull/2420#discussion_r1241813541 for a more detailed explanation -if class * -keepclasseswithmembers,allowobfuscation,allowoptimization class <1> { (); @com.google.gson.annotations.SerializedName ; }