【发布时间】:2017-08-04 19:52:39
【问题描述】:
[![Proguard规则][gson解析2.8.0版]][android官方volley 1.0.0版]
启用 ProGuard 规则后,Gson 解析不起作用。我使用了 Volley 1.0.0 的正式版和 Gson 2.8.0 版。因此,每当我启用 ProGuard 规则时,Gson 解析都不起作用。我还在proguard-rules.pro 文件中添加了所需的规则,但它仍然无法正常工作。
依赖
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.android.volley:volley:1.0.0'
ProGuard 规则:
-ignorewarnings
-keep class org.joda.** { *; }
-dontwarn org.joda.convert.FromString
-dontwarn org.joda.convert.ToString
-dontwarn org.joda.convert.**
-dontwarn org.joda.time.**
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *; }
-dontwarn org.mockito.**
-dontwarn sun.reflect.**
-dontwarn android.test.**
-dontwarn java.lang.management.**
-keepattributes Signature
-keep class com.google.gson.examples.android.model.** { *; }
-keep class com.google.gson.**{ *; }
-dontwarn com.fasterxml.jackson.**
-keep class com.fasterxml.jackson.** { *; }
解析方法
private static void verifyResponse(final String response, final RequestCode requestCode, final IListener listener) throws IOException, ClassNotFoundException {
if (listener != null) {
ResponseStatus responseStatus;
try {
JSONObject jResult = new JSONObject(response);
if (jResult.has("d")) {
String strResult = jResult.getString("d");
jResult = new JSONObject(strResult);
Debug.trace("ResponseStatusA " + jResult.toString());
}
responseStatus = gson.fromJson(new JSONObject(jResult.toString()).toString(), ResponseStatus.class);
Debug.trace("ResponseStatusB " + responseStatus.getStatus());
processSuccess(jResult.toString(), responseStatus, requestCode, listener);
/* if (responseStatus.isFail()) {
processError(responseStatus, listener);
} else {
if (responseStatus.isSuccess()) {
listener.onHideProgressDialog();
processSuccess(jResult.toString(), responseStatus, requestCode, listener);
}
}*/
} catch (JsonSyntaxException | JSONException e) {
e.printStackTrace();
}
}
}
【问题讨论】:
标签: android-volley android-proguard android gson