ProGuard可使班级成员保持“未使用"状态.注解 [英] ProGuard to keep class members with "unused" annotation

查看:126
本文介绍了ProGuard可使班级成员保持“未使用"状态.注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序依赖于具有类成员的库

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

@SuppressWarnings("unused")

注释.当我使用proguard-rules.pro时,

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

minifyEnabled true

在gradle文件中,使用

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

,通过

"proguard-rules.pro" 

推荐答案

@SuppressWarnings注释具有源级别的保留,因此它在ProGuard处理的实际类文件中不存在.

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

如果您需要在运行时保留这些字段,则必须自己添加特定的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>;
}

这篇关于ProGuard可使班级成员保持“未使用"状态.注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆