gpt4 book ai didi

java - 当我在 GSON(使用枚举)上运行 Proguard 时应用程序崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:47 24 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用 GSON 来解析数据。我在我的模型对象中添加了一个枚举。添加枚举后,我的应用程序开始崩溃。当我将 runProguard 设置为 false 时,一切正常。当程序为真时,我做了我能在互联网上找到的一切来解决问题。但仍然没有运气。

我已经在 proguard-rule 文件中做了以下事情

-keep class com.google.** { *; }

-keepattributes *Annotation*
-keepattributes Signature

-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }

枚举示例:

public enum TypeX {
@SerializedName("live")
LIVE,

@SerializedName("upcoming")
UPCOMING,

@SerializedName("replay")
REPLAY; }

我的堆栈跟踪

java.lang.AssertionError
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>(Unknown Source)
at com.google.gson.internal.bind.TypeAdapters$26.create(Unknown Source)
at com.google.gson.Gson.getAdapter(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(Unknown Source)
at com.google.gson.Gson.getAdapter(Unknown Source)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(Unknown Source)
at com.google.gson.Gson.getAdapter(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(Unknown Source)
at com.google.gson.Gson.getAdapter(Unknown Source)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(Unknown Source)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(Unknown Source)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(Unknown Source)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(Unknown Source)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Unknown Source)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Unknown Source)
at com.google.gson.Gson.toJson(Unknown Source)
at com.google.gson.Gson.toJson(Unknown Source)
at com.google.gson.Gson.toJson(Unknown Source)
at com.google.gson.Gson.toJson(Unknown Source)
at com.theice.gsonapp.app.MainActivity.a(Unknown Source)
at com.theice.gsonapp.app.MainActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

这应该通过使用以下规则来解决:

-keepclassmembers enum * { *; }

或使用以下内容:

-keepclassmembers enum com.your.package.** { *; }

相关回答:https://stackoverflow.com/a/30167048/4758255

关于java - 当我在 GSON(使用枚举)上运行 Proguard 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com