android - 使用 GSON 时的 Proguard 问题

标签 android json gson

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

相关文章:

java - 使用 GSON 将 JSON 解析为 Java 对象

android - 错误: Failed to find 'ANDROID_HOME' environment variable when building apk using ionic

c# - JsonSerializerSettings 中指定的错误是否捕获所有异常

c# - 获取InvalidOperationException错误堆栈跟踪只有一行

java - json对象与java对象不一致时的gson.fromJson

java - 如何将 JSON 文件反序列化为具有嵌套类的 ArrayList?

android - 使用 actionscript3 检索 android 的 IMEI

java - 当我启动并启动时,我的应用程序崩溃了?

java - Android: ExpandAnimation With Fragment

javascript - 如何将外部 JSON 文件读入我的 html/javascript 测验