Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit not working on release version of app

I am using Retrofit in my app. Everything is working fine but when I create the release version of the app some calls aren't working.

What could the problem be? I already disabled minifyEnabled in my gradle file.

Edit: Found the real problem: I get the user data by a specific API call. I map this on the following class:

String ID;
String user_login;
String user_nicename;
String user_email;
String display_name;

For some reason, all the fields are filled except for ID. When I don't use release but debug the ID field gets filled.

like image 380
Bart Bergmans Avatar asked Apr 18 '18 12:04

Bart Bergmans


4 Answers

Try this:

-dontnote okhttp3.**, okio.**, retrofit2.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }

If above code not work then add @Keep annotation to your model class like this.

import androidx.annotation.Keep;

@Keep
public class Blog {

    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
like image 156
Pooja Avatar answered Oct 28 '22 14:10

Pooja


make sure have provided specific rules for retrofit. If you've enabled minifyEnabled=truethen

add below rules for retrofit in your proguard-rules.pro file

-dontnote okhttp3.**, okio.**, retrofit2.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
like image 28
Dhiren Avatar answered Oct 28 '22 12:10

Dhiren


For me, I was trying to fetch data using retrofit. My model was like following:

data class ChecksumResponseEntity(
    @SerializedName("code")
    val code: Double,
    @SerializedName("message")
    val message: String,
    @SerializedName("checksum")
    val checksum: String
)

The issue was that all values were being initialized to null instead of what was coming in response.

A added following in proguard file but it did not help me:

-dontnote okhttp3.**, okio.**, retrofit2.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }

Than I tried adding @Keep annotation to my Model file as shown below:

@Keep
data class ChecksumResponseEntity(
    @SerializedName("code")
    val code: Double,
    @SerializedName("message")
    val message: String,
    @SerializedName("checksum")
    val checksum: String
)

Not sure why it was happening but adding @Keep fixed it for me.

like image 4
Tarun Deep Attri Avatar answered Oct 28 '22 13:10

Tarun Deep Attri


Keep the package as it is, where the DTOs are :

-keep class com.test.apppackagename.retrofit.dto** {
    *;
}
like image 1
Maifee Ul Asad Avatar answered Oct 28 '22 14:10

Maifee Ul Asad