在proguard中,如何保留一组类的方法名称?

问题描述 投票:22回答:2

我正在使用proguard来混淆我的android应用程序。 android应用程序包含一些本机代码,可以对完全限定的java方法进行回调。我不需要混淆这些类及其方法的名称。下面正确地保留了类名,但不保留方法名。

-keep public class com.me.dontobf.*
-keepnames public class com.me.dontobf.*
java android proguard
2个回答
54
投票

对于本地方法:ProGuard manual > Examples > Processing native methods

# note that <methods> means any method
-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

在这种情况下,对于回调方法:ProGuard manual > Examples > Processing callback methods

-keep class mypackage.MyCallbackClass {
    void myCallbackMethod(java.lang.String);
}

或者,例如,如果所有公共方法都可能是回调方法:

-keep class mypackage.MyCallbackClass {
    public <methods>;
}

您可能还需要保留方法描述符中出现的任何程序类。


2
投票

尝试:

-keepclasseswithmembernames class * {
    native <methods>;
}

从ProGuard手册:http://proguard.sourceforge.net/manual/examples.html#native

© www.soinside.com 2019 - 2024. All rights reserved.