How to tell Proguard to obfuscate class names

I would like proguard to obfuscate classnames. I have this line in Proguard.cfg

-keepclasseswithmembers class * {
public static <fields>;
}

-keepnames class * implements java.io.Serializable
-keep public class com.google.**

And I notice that what is not obfuscated is the class names. So running jdgui i see com/test/abcd/ActualClass.java public class ActualClassName extends Activity etc

moreover I see methods returning real classnames. like

 ActualClassname aa();

and imports statements like

 import com.abcd.ActualClassName

How do I get Proguard to obfuscate the classname itself. Its not just for Activities that I see this my Adapters are not being obfuscated. Well there is obfuscation going on but not class names.

Is the rules above what prevents the class names from being obfuscated?

Update: i have since removed the rules above and a Utility class that does not extend anything from Android is not being obfuscated. I'm now wondering if there is some implicit rule about keeping class names of classes that are referenced from classes that are being kept like Activity derivied classes? The classes whose names are not being obfuscated have a few things in common:

1) Static methods 2) Import of other types which are kept like those deriving from activity or serializable. 3) They have methods with parameters of other classes (Some of which might need to be kept).

However there is no where that I am specifically requesting that these utility classes should be kept.


There are several class that appear in your code that must retain the same fully qualified class name in order for android to be able to find them. One example as above are all Activity classes, as they are defined in the manifest by their full name as a String. If proguard were to rename the class then Android would no longer be able to find them.

The typical Proguard config will refer to the Proguard config in the Android SDK which will include several important lines like this one:

-keep public class * extends android.app.Activity

I think your problem is coming from your first line: '-keepclasseswithmembers' includes the class name, so in your case any class with a static field will keep its name. Changing it to simply '-keepclassmembers' will obfuscate the class names while leaving the static fields intact(which I'm assuming you want to do).

That said, I'm not sure why you want to do this, though. If you're trying to preserve the static variable names, shouldn't you want to preserve the class names as well, seeing as how that's how you'll be accessing the static fields? Why are you trying to preserve all of your static variable names?

链接地址: http://www.djcxy.com/p/59384.html

上一篇: 阅读csv方向的熊猫

下一篇: 如何告诉Proguard混淆类名