29

I am using proguard to obfuscate my android application. The android application contains some native code, which makes callbacks to fully qualified java methods. I need to not obfuscate these classes and the names of their methods. The below properly keeps the class names, but not the method names.

-keep public class com.me.dontobf.*
-keepnames public class com.me.dontobf.*
ab11
  • 19,770
  • 42
  • 120
  • 207

2 Answers2

65

For native methods: ProGuard manual > Examples > Processing native methods

# note that <methods> means any method
-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

In this case, for callback methods: ProGuard manual > Examples > Processing callback methods

-keep class mypackage.MyCallbackClass {
    void myCallbackMethod(java.lang.String);
}

Or e.g., if all public methods may be callback methods:

-keep class mypackage.MyCallbackClass {
    public <methods>;
}

You probably also need to keep any program classes that occur in the method descriptors.

Dico
  • 1,296
  • 1
  • 9
  • 8
Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
2

Try:

-keepclasseswithmembernames class * {
    native <methods>;
}

From the ProGuard manual: http://proguard.sourceforge.net/manual/examples.html#native

Marc Bernstein
  • 11,423
  • 5
  • 34
  • 32
  • 2
    Your suggestion doesn't work for me. I need to preserve method names of non-native methods which are called from native code. Your suggestion keeps class names of classes that contain native methods. – ab11 Oct 24 '11 at 20:22