防止Proguard删除未使用的属性

时间:2015-09-11 13:29:38

标签: android proguard greendao android-proguard

我有一个班级:

public static class Properties {
    public final static Property Id = new Property(0, String.class, "id", true, "ID");
    public final static Property Name = new Property(1, String.class, "name", false, "NAME");
    public final static Property Email = new Property(2, String.class, "email", false, "EMAIL");
    public final static Property ValidatedAt = new Property(3, long.class, "validatedAt", false, "VALIDATED_AT");
};

以下的规则:

-keep class **$Properties

但是当我在这里组装发布版本时输出:

public class UserDao$Properties
{
  public static final f a;
  static
  {
    a = new f(0, String.class, "id", true, "ID");
    new f(1, String.class, "name", false, "NAME");
    new f(2, String.class, "email", false, "EMAIL");
    new f(3, Long.TYPE, "validatedAt", false, "VALIDATED_AT");
  }
}

(来自反编译的APK)

请注意,只有Id字段已设置,其他三个字段未设置(即使它们的构造函数存在)。

其他三个字段未在代码中使用,但由GreenDAO使用反射。

如何防止删除其他三个字段?

我试过了

-keepclassmembers class **$Properties {
    public final static Property *;
}

以及上述规则但不起作用。

1 个答案:

答案 0 :(得分:1)

试试这个

-keepclassmembers class **$Properties {
    public static <fields>;
}