问题描述
我想用自定义的 @Keep
注释来注释我的应用程序中的一些接口并配置 ProGuard 以便
I would like to annotate some interfaces in my application with a custom @Keep
annotation and configure ProGuard so as to
- 不要混淆带注释的接口及其方法,
- 不要在实现类时混淆这些接口方法的实现.
我尝试过类似的东西
# 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 *
但显然语法无效.我尝试了其他方法,但 ProGuard 文档及其示例并不清楚确切的语法以及在哪些情况下可能会发生的情况.
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.
推荐答案
抱歉回答我自己的问题,但我在玩的时候碰巧碰到了解决方案.其实比我想象的要简单得多:
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 * {
*;
}
上面的语法似乎保留了完整的接口(类名、方法名)加上所有实现的方法名,如果我考虑一下,这是合乎逻辑的,因为如果我确实实现了一个接口,我无法更改(混淆)方法名无论如何.
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.
这篇关于ProGuard:保留用@Keep 注释的接口实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!