Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep specific Annotation with proguard

I have two types of annotation in my project: Annotation1 and Annotation2. Both are runtime annotations. So, my question is how to keep only Annotation1 and strip Annotation2?

Example:

class Test {
    @Annotation1
    @Annotation2
    String name;
}

I want Annotation2 to be removed from all fields and Annotation1 to be kept everywhere.

I can't find whether this is possible. I only know how to keep all annotations using:

-keepattributes *Annotation*

Is this possible? If not, why?

like image 986
Orest Savchak Avatar asked Oct 29 '22 22:10

Orest Savchak


1 Answers

ProGuard automatically removes annotations from the classes/fields/methods if the corresponding annotation classes are not used (retrieved, cast, invoked,...) elsewhere. You can't force ProGuard to remove annotations, but you can tell it to keep seemingly unused annotations:

-keep @interface com.example.MyAnnotation
like image 127
Eric Lafortune Avatar answered Nov 09 '22 11:11

Eric Lafortune