【问题标题】:Prevent Proguard from removing unused Properties防止 Proguard 删除未使用的属性
【发布时间】:2015-09-11 13:29:37
【问题描述】:

我有一堂课:

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");
};

还有以下proguard规则:

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

与上面的规则一起,但它不起作用。

【问题讨论】:

  • 您是否尝试过明确保留Properties 类的内容:-keep class **$Properties { *; }?或者,您也可以尝试保留内部类:-keepattributes InnerClasses.

标签: android proguard greendao android-proguard


【解决方案1】:

试试这个

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-18
    • 2011-09-10
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    相关资源
    最近更新 更多