ProGuard to keep class members with “unused” annot

2019-09-16 12:39发布

The app has dependency on library, which has class members with

@SuppressWarnings("unused")

annotation. When I made use of proguard-rules.pro by,

minifyEnabled true

in gradle file, the members with above annotations are not found at runtime, with

NoSuchFieldError error. 

How to keep those members from that library package, with annotation

@SuppressWarnings("unused")

, through

"proguard-rules.pro" 

2条回答
迷人小祖宗
2楼-- · 2019-09-16 13:23

try using something like this for the specific class you are using:

-dontwarn {package name}.{class name}
-keep class {package name}.{class name} { *; }
-keep interface {package name}.{class name} { *; }
查看更多
Lonely孤独者°
3楼-- · 2019-09-16 13:24

The @SuppressWarnings annotation has source-level retention, thus it is not present in the actual class file that is processed by ProGuard.

You will have to add specific ProGuard rules yourself to keep these fields if you need them at runtime.

To keep all fields of a class you can use a rule like this:

-keep class xxx.yyy {
    <fields>;
}
查看更多
登录 后发表回答