Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard - Keep all classes and methods names, but obfuscated Fields

I trying to keep all classes and methods names, but obfuscated all the fields in my project.

For example, this code:

public class MyClass {
    private int    myInt;
    public String  myString;

    void myMethod() {
        // Method code;
    }
}

Should turn into this code

public class MyClass {
    private int    a1;
    public String  a2;

    void myMethod() {
        // Obfuscated method code;
    }
}

Note that the class name and method name doesn't get obfuscated, but the field name does.

I'm guessing it is some sort of combination with keepnames and keepclassmembernames, but I'm not sure what is the correct one.

like image 396
Danny Avatar asked Aug 31 '15 10:08

Danny


1 Answers

Try below if you can add access modifier to the method you want to keep , e.g you want to keep all public methods.

-keep class MyClass
-keepclassmembers class MyClass  {
    public <methods>;  
}  
like image 68
lorcel Avatar answered Nov 07 '22 20:11

lorcel