[英]Getting wrong keys in json while calling retrofit after enabling proguard
when i call retrofit without proguard i got json like following: D/OkHttp: {"UserPin":"123456","password":"123456"}
and after adding proguard it gives following json: D/OkHttp: {"a":"123456","b":"123456"}
when i call retrofit without proguard i got json like following: D/OkHttp: {"UserPin":"123456","password":"123456"}
and after adding proguard it gives following json: D/OkHttp: {"a":"123456","b":"123456"}
Proguard changes the keys in json Proguard 更改 json 中的键
This is my code:-这是我的代码:-
private void doLogin(String userPin, String password) {
startProgress();
LoginUser loginUser = new LoginUser(userPin, password);
Call<Login> call = MyApplication.apiInterface.doLogin(loginUser);
call.enqueue(new Callback<Login>() {
@Override
public void onResponse(Call<Login> call, Response<Login> response) {
finishProgress();
try {
setLoginResponse(response.body());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<Login> call, Throwable t) {
finishProgress();
try {
setLoginResponse(null);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
Please help me请帮我
You should add proguard
rule.您应该添加proguard
规则。
-ignorewarnings
-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
And Login class并登录class
-keep class package_name.Login** { *; }
-keepclassmembers class package_name.Login** { *; }
For GSON Proguard
, Try this对于GSON Proguard
,试试这个
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
##---------------End: proguard configuration for Gson ----------
Check to make sure are have proguard configured for gson, too.检查以确保也为 gson 配置了 proguard。 You need to make sure POJO used with gson are not obfuscated and annotations are not stripped.您需要确保与 gson 一起使用的 POJO 未被混淆并且注释未被剥离。
Note: You should replace com.google.gson.examples.android.model.** { *; }
注意:您应该替换com.google.gson.examples.android.model.** { *; }
com.google.gson.examples.android.model.** { *; }
with your model classes in the example below.在下面的示例中使用您的com.google.gson.examples.android.model.** { *; }
类。
From the gson example proguard config --来自 gson 示例 proguard 配置——
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
##---------------End: proguard configuration for Gson ----------
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.