同时采用GSON Proguard的问题问题、GSON、Proguard

2023-09-05 07:00:45 作者:厌弃°

我在我的应用程序中使用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  ----------