How to not obfuscate interface methods & its parameters using Proguard in Android?

我只是一个虾纸丫 提交于 2019-12-21 03:32:36

问题


I have the following code:

public class MyClass {
    public void method1(Integer marks) {

    }

    private String method3(String name){

    }
    public interface interface1 {
        void method4(Integer ID);
        void method5(Integer rate, boolean status);
    }
}

I have used progaurd-rules.pro

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-keepparameternames

-keep public class *
-keepclassmembers public class *{
   public *;
 }
-keep public interface packageName.MyClass$interface1 { *; }

Obfuscated code as below:

public class MyClass {
    public void method1(Integer marks) {

    }

    private String a(String var1){

    }
    public interface interface1 {
        void method4(Integer var1);
        void method5(Integer var1, boolean var2);
    }
}

I want the interface methods variables (ID, rate & status) not to obfuscate. i.e as below

public interface interface1 {
    void method4(Integer ID);
    void method5(Integer rate, boolean status);
} 

How can it be possible?


回答1:


You could keep method's arguments by adding extra flags to -keepattributes. They look like this:

-keepattributes LocalVariableTable,LocalVariableTypeTable

Unfortunately, this keeps arguments from obfuscation not only in the interface you want, but in the entire project. Maybe that's fine for you.

If you're using a default proguard configuration shipped along with Android SDK then you could also use a special annotation to prevent some classes from obfuscation. Check it out.




回答2:


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

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

In case if your interface is not public.

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


来源:https://stackoverflow.com/questions/35290615/how-to-not-obfuscate-interface-methods-its-parameters-using-proguard-in-androi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!