Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.* 
like image 882
ab11 Avatar asked Oct 24 '11 18:10

ab11


People also ask

How do you keep all classes in ProGuard?

-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.

What is keep class in ProGuard?

Specifies classes and class members whose names are to be preserved, if they aren't removed in the shrinking phase. For example, you may want to keep all class names of classes that implement the Serializable interface, so that the processed code remains compatible with any originally serialized classes.

Does ProGuard obfuscate package name?

Obfuscating package names myapplication. MyMain is the main application class that is kept by the configuration. All other class names can be obfuscated. Note that not all levels of obfuscation of package names may be acceptable for all code.

Does ProGuard remove unused classes?

ProGuard Facts:Helps to remove unused classes, members & fields. It removes unused codes from your libraries as well. (Which means, any method or field that is not referenced anywhere will be removed by ProGuard Shrinker). Helps to reduce the build size by obfuscating the classes, methods, & fields with short names.


1 Answers

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.

like image 155
Eric Lafortune Avatar answered Sep 23 '22 19:09

Eric Lafortune