Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 573
Pushpa Avatar asked Feb 09 '16 11:02

Pushpa


People also ask

What is code shrinker?

Code shrinking (or tree-shaking): detects and safely removes unused classes, fields, methods, and attributes from your app and its library dependencies (making it a valuable tool for working around the 64k reference limit).

What is minify in Android?

minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.

How to obfuscate Android code?

You can obfuscate Android code to provide security against reverse engineering. You can use the Android ProGuard tool to obfuscate, shrink, and optimize your code. Obfuscated code can be more difficult for other people to reverse engineer.

What is R8 in Android?

R8 is an app shrinking tool that is used to reduce the size of your application. This tool present in Android Studio works with the rules of Proguard. R8 will convert your app's code into optimized Dalvik code.


1 Answers

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.

like image 158
andrei_zaitcev Avatar answered Sep 21 '22 06:09

andrei_zaitcev