我在我的应用程序中使用 Gson,为此,我使用了一些名称与使用 Json 时相同的类。我的应用程序运行良好,但是在编写混淆器时,应用程序崩溃,我猜某些类正在缩小。 我的错误是:
java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to com.sample.package.GsonClass
最佳答案
您需要将这些行添加到您的混淆器中,以便在签署您的应用程序时保留 gson 类。
##---------------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 ----------
关于android - 使用 GSON 时的 Proguard 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16563916/