android - 防止 Proguard 删除未使用的属性

标签 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 *;
}

与上述规则一致,但它不起作用。

最佳答案

试试这个

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

关于android - 防止 Proguard 删除未使用的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32524709/

相关文章:

android - CustomView 扩展 RelativeLayout

java.lang.NoSuchMethodException : [class android. app.Activity,int]

android - 如果使用 Proguard,Google Place API Status 会返回 NULL

java - greendao 设置父类(super class)

android - 处理双向 1 :m in Green-DAO 的正确方法

android - 如何为 kontakt.io sdk 实现后台服务?

android - 在 WebView 中更改 URL 而不是打开浏览器

java - 使用绑定(bind)程序调用服务方法时如何使用线程

java - 用 proguard 混淆文件名

android - GreenDAO:存储其他实体中的实体列表