9

I would like to annotate some interfaces in my application with a custom @Keep annotation and configure ProGuard so as to

  • not obfuscate the annotated interface and its methods,
  • not obfuscate implementations for those interface methods in 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 really clear about the exact syntax and what is possible under which circumstances.

kriegaex
  • 63,017
  • 15
  • 111
  • 202

2 Answers2

7

Sorry for answering my own question, but I just happened to bump into the solution when playing around. Actually it is 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> on an interface keep clause, maybe because ProGuard only filters for actual method implementations, not mere method declarations as can be found in interface declarations.

The above syntax seems to keep the full interface (class name, method names) plus all implementing method names, which is logical if I think about it, because if I do implement an interface I cannot change (obfuscate) the method names anyway.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • You can find a series of examples in examples/annotations/lib/annotations.pro in the ProGuard distribution. The specifications are intended to look like Java, but with wildcards. Note that the wildcard works fine for interfaces as well. – Eric Lafortune Mar 19 '14 at 00:53
  • Thanks Eric, someone else also said that before, but deleted his answer because it did not directly solve the problem. I have looked at that resouce already and even though it does not really answer the question it gave me lots of ideas. I also noticed that probably my syntax error `interface @Keep` instead of `@Keep interface` was the real problem, not the usage of ``. – kriegaex Mar 19 '14 at 05:45
0

This helped a similar situation I had:

Proguard stops Javascript in WebView from working

I imagine the principle would be the same...

Community
  • 1
  • 1
user3197788
  • 165
  • 4
  • 14
  • Thanks, but the answer does not apply to my question. My problem are not annotated methods but annotated interfaces. – kriegaex Mar 18 '14 at 08:59