Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep class method names that override\implements another method from being obfuscated?

If I have a Class B that implements Interface A and Proguard isn't aware of the existence of that interface, How can I keep the names of the methods that implements interface A's abstract methods?

Please notice that I want to keep the method names, but I do want their content to be obfuscated.

Update: This is what I have (Please notice the comments):

public class MyService extends Service {

   // an anonymous class that implements ServiceConnection 
   private ServiceConnection myConnection = new ServiceConnection()
   {
      // don't change the following method's name
      @Override
      public void onServiceConnected(ComponentName className, IBinder service)
      {
          // I want this section to be obfuscated
      }

}

I want a general solution for these kind of cases - I don't want to state interfaces names in the ProGuard configuration.

like image 211
Ron Tesler Avatar asked Jul 16 '13 11:07

Ron Tesler


1 Answers

  • Keeping all public class names and keep (prevent obfuscation) of their public and protected methods.
  • In non-public classes and keep (prevent obfuscation) all public and protected methods. This will keep the methods that might implement or extend other methods, from being obfuscated.
  • Don't keep the local variables attributes (make sure that "LocalVariableTable" and "LocalVariableTypeTable" are not stated in the "-keepattributes" option).

So your .pro file should look like this -

#Keeping all public class names and keep (prevent obfuscation) of their public and protected methods
-keep public class * {
    public protected <methods>;
}

# Keep (prevent obfuscation) all public and protected methods in non-public classes.
# Notice that the non-public class names will still get obfuscated
-keepclassmembers !public class * {
    public protected <methods>;
}

# Don't keep the local variables attributes (LocalVariableTable and LocalVariableTypeTable are dropped).
-keepattributes Exceptions,Signature,Deprecated,SourceFile,SourceDir,LineNumberTable,Synthetic,EnclosingMethod,RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations,AnnotationDefault,InnerClasses,*Annotation*
like image 133
Ron Tesler Avatar answered Sep 28 '22 06:09

Ron Tesler