Can not recieve data when use retrofit and set minifyEnabled true

33 views Asked by At

I try to get data from server with android, i work well when is set minifyEnabled false but when i set minifyEnabled true i can not revice data, it all is null

My version java is 17, My retrosit version is

com.squareup.retrofit2:retrofit:2.6.0
com.squareup.retrofit2:converter-gson:2.5.0
com.squareup.okhttp3:logging-interceptor:3.12.0

I try some other answer on stackoverflow

-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}
-dontwarn retrofit2.**
-dontwarn org.codehaus.mojo.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*

-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepattributes EnclosingMethod

-keepclasseswithmembers class * {
    @retrofit2.* <methods>;
}

-keepclasseswithmembers interface * {
    @retrofit2.* <methods>;
}

My code to call api

interface ApiService {
    @POST("/ipay-decode/")
    suspend fun handleDataTest(
        @Body requestBody: BaseRequest,
    ): BaseResponse
}

data class BaseRequest(
    @SerializedName("encrypted")
    val encrypted: String
)

open class BaseResponse {
    @SerializedName("message")
    var message: String = ""
}

Can anyone help me with any solution?

1

There are 1 answers

0
Jaxon M On BEST ANSWER

This is due to your models getting obfuscated when minify is enabled. To fix add the path to your models package to your Proguard rules.

Something like this should work:

-keep class your.package.name.model.** { *; }
-keepattributes Signature
-keepattributes *Annotation*
-keep class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    private void readObjectNoData();
    Object writeReplace();
    Object readResolve();
}