Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I receive null response using retrofit in release mode but in debug mode everything works fine

I use retrofit in application for calling http requests and use gson for parsing json objects. I get response correctly in debug mode, but in build with release mode my response is null and my app doesn't work any more

like image 480
Hamidreza Shadabkia Avatar asked Oct 29 '25 17:10

Hamidreza Shadabkia


2 Answers

I found the answer after a while ... I use proguard for release mode so because of Obfuscation the model fields names changes so gson cant parse the http response, the best way for preventing this problem is using @SerializedName("field_name") annotation in fields to could be parsed after Obfuscation.

like image 104
Hamidreza Shadabkia Avatar answered Oct 31 '25 07:10

Hamidreza Shadabkia


Probably you have proguard enabled for release mode. Check your app gradle build and see if minify is enabled. If you disable it your code won’t get obfuscate and you will no longer have any issues with release build.

If you do want to obfuscate your code which is good for security of your app then you have to find proguard rules for every library you have included in your app. Then you have to add those rules in your proguard rules file. Also you have to skip POJO classes from getting obfuscate.

Common proguard rules for most of the libraries can be found in this file created by @jemshit

https://gist.github.com/jemshit/767ab25a9670eb0083bafa65f8d786bb

like image 37
xsheru Avatar answered Oct 31 '25 08:10

xsheru