【问题标题】:In proguard, how to preserve a set of classes' method names?在proguard中,如何保存一组类的方法名?
【发布时间】:2011-12-14 08:55:54
【问题描述】:

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

-keep public class com.me.dontobf.*
-keepnames public class com.me.dontobf.*

【问题讨论】:

    标签: java android proguard


    【解决方案1】:

    对于本机方法: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

    【讨论】:

    • 你的建议对我不起作用。我需要保留从本机代码调用的非本机方法的方法名称。您的建议保留包含本机方法的类的类名。
    猜你喜欢
    • 1970-01-01
    • 2020-04-23
    • 2012-06-13
    • 2015-03-25
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    相关资源
    最近更新 更多