防止 Proguard 删除未使用的属性
Prevent Proguard from removing unused Properties
我有一个 class:
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
但是当我assemble这里的发布版本是输出:
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>;
}
我有一个 class:
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
但是当我assemble这里的发布版本是输出:
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>;
}