Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Proguard in Android throws error Gson

I am trying to implement Proguard for my Android project. Am using Android Studio for doing the same. But finding lot of difficulties while implementation. Is there a good tutorial to overcome all the issues. In the below code which I have used got an exception like cannot be cast. Can anyone help me to get rid of this issue.

In my proguard-rules.txt I have used the below lines too. But it dint resolve my issue

-keep class com.google.gson.**{*;}
-dontwarn com.google.gson.**


public class Home_CityDet implements Serializable{

private static final long serialVersionUID = 1L;
@SerializedName("key")
public String key;
@SerializedName("value")
public String value ;   
}

java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to webservices.responses.Home_CityDet
like image 970
Munchoo Avatar asked Aug 08 '26 02:08

Munchoo


1 Answers

I had to add to the progaurd configuration:

-keepattributes Signature
-keepattributes *Annotation*
-keep class Home_CityDet  {
*;
}

and the error magically disappeared

like image 97
nont Avatar answered Aug 11 '26 00:08

nont



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!