c# - Signed apk is changing post parameters name -
i have app , c# web api app calls using retrofit2. i'm facing problem while making post call api, parameter names in call changing "a" , "b" instead of there actual names.
apiinterface:
@post("users/add") call<string> createuser(@body usersignupmodel user);
setting retrofit:
gson gson = new gsonbuilder() .setlenient() .create(); retrofit = new retrofit.builder() .baseurl(configuration.api_url) .addconverterfactory(gsonconverterfactory.create(gson)) .client(get_httpclient()) .build();
usersignupmodel:
public class usersignupmodel { public string username; public long phonenumber; }
making request:
usersignupmodel.username = username.gettext().tostring(); usersignupmodel.phonenumber = long.parselong(number.gettext().tostring()); client.createuser(usersignupmodel, callback);
i have setup fiddler intercept request i'm getting app , below results:
1. when click debug or run on android studio
2. when generate signed apk , make request
requests failing because of this. appreciated.
thank you.
generating signed .apk trigger proguard (if it's enabled). obfuscate classes , such.
there 2 ways how can fix case:
option 1: using @serializedname
change usersignupmodel.java, explicitely stating name of variables:
import com.google.gson.annotations.serializedname; public class usersignupmodel { @serializedname("username") public string username; @serializedname("phonenumber") public long phonenumber; }
option 2: changing proguard-rules.pro
file
add following rule proguard-rules.pro
file, assuming usersignupmodel.java
inside model package:
-keep class com.<packagename>.model.** { *; }
Comments
Post a Comment