Annada
Annada

Reputation: 1085

ProGuard to keep class members with "unused" annotation

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" 

Upvotes: 0

Views: 1529

Answers (2)

T. Neidhart
T. Neidhart

Reputation: 6200

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

Upvotes: 2

masoud vali
masoud vali

Reputation: 1536

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

Upvotes: 0

Related Questions