在proguard混淆期间如何保留除一个以外的所有公共成员?

时间:2012-09-08 18:06:28

标签: java obfuscation proguard

来源示例:

// this is package visible interface
interface MyInterface {
    void foo();
}

public class MyClass1 implements MyInterface {
    // some public class members which should not be obfuscated
    // ...     

    // this is MyInterface implementation, this method should be obfuscated:
    void foo() {}
}

// other classes which implement MyInterface
...

如何在MyClass1和其他类中保留所有公共成员,同时仅混淆MyInterface.foo()实现。

2 个答案:

答案 0 :(得分:2)

考虑到只有一种方法需要混淆,为什么不将void foo()方法重命名为void y()(或者你喜欢的随机字母)?

如果你真的无法处理在调试时记住一个奇怪命名的方法,你必须单独-keep所有其他方法。

另一种选择是将方法提取到另一个类,或者创建一个子类,但这可能不是你想要的。

答案 1 :(得分:1)

ProGuard不提供任何快捷方式来指定除一个方法之外的所有方法。你必须指定你需要的那些。据推测,你有必要保留它们。例如,如果它们实现了另一个接口,您可以轻松指定保留此其他接口的所有方法。

请注意,-keep规范是指类/字段/方法的名称,而不是方法的代码:

ProGuard手册>用法> Overview of -keep options

相关问题