项目中使用Gson解析json数据,未做混淆处理时,网络访问及解析json数据正常。作代码混淆时,依据官方demo,配置Gson的混淆。混淆后,网络访问出现了问题,数据不能正常加载。Debug跟踪发现,网络访问获取数据正常,在Gson解析时出现了问题。很撸google发现了问题所在。
<span style="font-size:14px;">
##---------------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
<em><strong><span style="color:#FF6666;">-keep class com.google.gson.examples.android