ProGuard to keep class members with “unused” annotation

时光毁灭记忆、已成空白 提交于 2019-12-12 04:33:26

问题


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" 

回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/40719577/proguard-to-keep-class-members-with-unused-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!