Retrofit body request is blank with Retrofit, when I use proguard and enable minify and shrinkresources

Add below line in your proguard-rules.pro File

-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

Also add below line in gradle.properties file.

android.enableR8=false

I face same issue and added above line in the file and its working for me.


This is what worked for me.

# Retrofit2
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}
-keepclassmembernames interface * {
    @retrofit2.http.* <methods>;
}

# GSON Annotations
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

For some reason, it didn't work without the GSON annotations settings, even when adding a @Keep annotation on the model class directly.


Add below line in proguard-rules

-keepclassmembers class <yourpackagename>.** { <fields>; }

replace yourpackagename with the directory path where all your model classes , like in my case

-keepclassmembers class com.demo.app.model.** { <fields>; }