同时采用GSON Proguard的问题 [英] Proguard issue while using GSON

查看:158
本文介绍了同时采用GSON Proguard的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用GSON和的是,我使用的一些班级,名字相同之一,使用JSON。我的应用效果很好,但在写ProGuard的,应用程序崩溃,我想一些类正在缩小。 我的错误是:

  

java.lang.ClassCastException:com.google.gson.internal.StringMap不能转换为com.sample.package.GsonClass

解决方案

您需要将这些线条,同时签署您的应用程序添加到您的ProGuard使GSON类保持。

  ## ---------------开始:ProGuard的配置GSON ----------
#GSON使用带有字段时,存储在一个类文件泛型类型的信息。 Proguard的
#删除默认情况下这些信息,因此其配置,以保持它的全部。
-keepattributes签名


#GSON特定的类
-keep类sun.misc.Unsafe {*; }
#-keep类com.google.gson.stream ** {*。 }

将被序列化#应用程序类/解串过GSON
-keep类com.google.gson.examples.android.model ** {*。 }

## ---------------结束:为GSON ProGuard的配置----------
 

I am using Gson in my application and for that, i am using some classes with name as same as the one in using Json. My application works well, But while writing proguard, application crashes, I guess some of the classes are shrinking. my error is :

java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to com.sample.package.GsonClass

解决方案

You need to add these lines to your proguard so that gson class is kept while signing your app..

##---------------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


# 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  ----------

这篇关于同时采用GSON Proguard的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆