Gau*_*tel 6 android gson android-volley android-proguard
[![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'
Run Code Online (Sandbox Code Playgroud)
混淆规则:
-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.** { *; }
Run Code Online (Sandbox Code Playgroud)
解析方法
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
您缺少以下规则ResponseStatus:
-keep class com.yourapp.yourpackage.ResponseStatus { *; }
Run Code Online (Sandbox Code Playgroud)
可能发生的情况是 ProGuard 混淆了方法和字段,ResponseStatus并且当 Gson 尝试将它们设置为它们的名称不再匹配时。请记住,您需要-keep class为与 Gson 一起使用的每个模型类制定一个规则。
| 归档时间: |
|
| 查看次数: |
2449 次 |
| 最近记录: |