ProGuard:使用@Keep注释接口的实现 [英] ProGuard: keep implementations for interface annotated with @Keep

查看:550
本文介绍了ProGuard:使用@Keep注释接口的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用自定义的@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 * {
    *;
}

显然,在接口keep子句上指定<methods>是错误的,可能是因为ProGuard仅针对实际方法实现进行过滤,而不仅仅是在接口声明中可以找到的方法声明.

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.

这篇关于ProGuard:使用@Keep注释接口的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆