Arik
Arik

Reputation: 6501

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.

Upvotes: 4

Views: 4387

Answers (2)

Arik
Arik

Reputation: 6501

  • 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*

Upvotes: 7

Shraddha
Shraddha

Reputation: 1052

I have writtern a blog for Progaurding the Android application. Please check the link below

http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/

ProGuard can do what you describe. If you don't want it to rename classes and methods, Please try the following one :

-keep,allowshrinking,allowoptimization class * { <methods>; }

Hope this helps

Upvotes: 0

Related Questions