java 在 proguard 中保留内部接口方法名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25654805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:24:23  来源:igfitidea点击:

Keep inner interface method names in proguard

javaandroidproguard

提问by VicVu

Lets say I have..

可以说我有..

public class SomeClass {


    public interface someInterface {

        public void firstMethod(String variable);


        public void secondMethod(String variable);


        public void thirdMethod();

    }
}

and I do..

我做..

-keep,includedescriptorclasses public class com.somepackage.SomeClass {
    <fields>;
    <methods>;
}

-keep public interface com.somepackage.someInterface {*;}

I end up with

我结束了

public interface someInterface {

        public void a(String variable);


        public void a(String variable);


        public void a();

    }

How do I ensure this interface's method names are not obfuscated while still obfuscating the rest of the class?

我如何确保这个接口的方法名称不被混淆,同时仍然混淆类的其余部分?

回答by Eric Lafortune

ProGuard uses the naming convention of Java bytecode, as seen in class file names and stacktraces. Therefore:

ProGuard 使用 Java 字节码的命名约定,如类文件名和堆栈跟踪所示。所以:

-keep public interface com.somepackage.SomeClass$someInterface {*;}

回答by Phileo99

I tried the following and it seemed to work:

我尝试了以下方法,它似乎有效:

-keep interface com.somepackage.SomeClass$someInterface

回答by SebastianX

For those who are looking for how to keep a custom annotation (which is defined in a @interface in java) retaining its all members,

对于那些正在寻找如何保留自定义注释(在 java 中的 @interface 中定义)保留其所有成员的人,

you should actually use like below to keep it:

您实际上应该使用如下所示来保留它:

-keep @interface com.your.annotation.interface. {*;}