Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell Proguard to keep annotation on methods

I'm using my own annotation:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Loggable { }

and obfuscate using Proguard. I use the -keepattributes *Annotation* in the Proguard configuration to keep the annotations.

At runtime, when I retrieve the annotation from an annotated class using someClass.getAnnotation(Loggable.class) everything works - I retrieve a non-null instance of my annotation.

However, when I want to apply the same to an annotated method of some class, I retrieve null from someMethod.getAnnotation(Loggable.class).

Is Proguard removing the annotations from methods? How do I tell it not to do so?

I'm using Proguard 4.7.

like image 375
NumberFour Avatar asked May 15 '15 13:05

NumberFour


People also ask

How do you keep a class in ProGuard?

-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.

What is ProGuard configuration?

ProGuard is a tool to help minify, obfuscate, and optimize your code. It is not only especially useful for reducing the overall size of your Android application as well as removing unused classes and methods that contribute towards the intrinsic 64k method limit of Android applications.

How do you use ProGuard GUI?

Graphical User InterfaceSpecify the obfuscation options. Specify the optimization options. Specify some options to get information. View and save the resulting configuration, and run ProGuard.


1 Answers

You need to use keepclassmembers parameter:

-keepclassmembers class ** {
  @com.yourpackage.Loggable public *;
}
like image 50
eleven Avatar answered Oct 20 '22 06:10

eleven