【问题标题】:How to keep Enum type fields in proguard?如何将枚举类型字段保留在 proguard 中?
【发布时间】:2016-05-02 02:48:39
【问题描述】:

这是我的实体类:

class Entity{
    private String id;
    Object content;
    private Type type;
    public enum Type{type1, type2, type3}
}

根据type 字段,我将相应的类传递给

gson.fromJson(json, <type1/2/3 class, depending on field type>);

但我正在使用 proguard,这会混淆类型值,所以我无法确定要使用哪个类。

我试图保留类型字段,但它没有保留。这是我的代码:

-keepclassmembers enum * { *; }
-keepclassmembers class com.mypkg.Entity {
    private java.lang.String id;
    private com.mypkg.Entity.Type type;
 }

我看到保留了 id,但没有保留 type 字段。

请帮忙。

【问题讨论】:

    标签: android enums gson proguard android-proguard


    【解决方案1】:

    我在使用 Kotlin 时遇到了同样的问题。尝试使用@Keep注解

    例子:

    enum class Color {
        @Keep RED,
        @Keep GREEN,
        @Keep BLUE
    }
    

    【讨论】:

      【解决方案2】:

      This thread 可能会有所帮助。

      -keep public enum com.mypkg.Entity$** {
          **[] $VALUES;
          public *;
      }
      

      【讨论】:

        猜你喜欢
        • 2016-01-16
        • 1970-01-01
        • 2021-06-08
        • 2011-09-11
        • 1970-01-01
        • 2021-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多