ProGuard: keep implementations of an interface annotated with @Keep

I would like to annotate some interfaces in my application with user @Keep annotation and configure ProGuard so that

  • does not obfuscate the annotated interface and its methods,
  • does not confuse the implementation of these interface methods when implementing classes.

I tried something like

 # Kept interfaces and all their methods -keep interface @com.foo.bar.annotation.Keep * { <methods>; } # Classes implementing kept interfaces -keep class * implements @com.foo.bar.annotation.Keep * 

but obviously the syntax is invalid. I tried other things, but the ProGuard documentation and its examples are not entirely clear about the exact syntax and capabilities under any circumstances.

+7
java interface annotations proguard
source share
2 answers

Sorry for the answer to my own question, but I just accidentally ran into a solution while playing. This is actually much simpler than I thought:

 # Annotated interfaces (including methods which are also kept in implementing classes) -keep @com.foo.bar.annotation.Keep interface * { *; } 

Obviously, it was wrong to specify <methods> in the interface clause, perhaps because ProGuard only filters to implement the actual methods, and not just the method declarations that can be found in the interface declarations.

The above syntax seems to support the full interface (class name, method names) plus all the implementation method names, which is logical if I think about it, because if I implement the interface, I cannot change (obfuscate) the method names in any case.

+5
source share

This helped me in a similar situation:

Proguard Stops Javascript in WebView

I guess the principle will be the same ...

0
source share

All Articles