In proguard, how to preserve a set of classes' method names?
Asked Answered
H

2

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.*
Heshvan answered 24/10, 2011 at 18:30 Comment(0)
S
69

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.

Showing answered 24/10, 2011 at 20:24 Comment(0)
V
2

Try:

-keepclasseswithmembernames class * {
    native <methods>;
}

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

Voidable answered 24/10, 2011 at 19:3 Comment(1)
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.Heshvan

© 2022 - 2024 — McMap. All rights reserved.