【问题标题】:Parsing through GSON with Proguard使用 Proguard 解析 GSON
【发布时间】:2023-03-23 08:40:02
【问题描述】:

我在使用 Proguard 的 Android 上遇到 GSON 问题。 APK已编译,安装在手机上。 应用程序没有崩溃,只是没有正确解析对象。

我记录了所有的数据,就是这样:

我得到了正确的字符串,其中包含要解析的数据。

(Cookie 值正确)

Token token = new Gson().fromJson(cookieValue, Token.class);

在这一行之后,我正在记录这个对象,它里面只有空值。

我的 Proguard GSON:

# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class com.google.gson.examples.android.model.** { *; }


-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keep public class com.google.gson

令牌规则:

 -dontwarn com.project.package.model.oauth.**

 -keep,allowshrinking class com.project.package.oauth.Token { *; }


是的,我试过这个配置https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg

有什么建议吗?

【问题讨论】:

    标签: android gson proguard


    【解决方案1】:

    在这一行:

    - keep,allowshrinking class com.project.package.oauth.Token { *; }
    

    你在破折号和保留之间真的有空格吗?如果是这样,把它拿出来看看是否有帮助。

    您可能还想删除前一个 dontwarn 行中破折号后的空格。

    【讨论】:

    • 不,我没有这些空格。发布修复。谢谢:)
    【解决方案2】:

    您可以在我的收藏中找到它: https://github.com/thientvse/awesome-mobile-collections/blob/master/README.md

    它将帮助您在 proguard 文件中配置几乎 lib。 希望对您的问题有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-04
      • 2011-02-12
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 1970-01-01
      相关资源
      最近更新 更多