I'm building an android framework and I need to obfuscate and shrink the jar to ship it to users.
I'm using the proguard tool included in the android SDK and I have the following requirements for the output jar:
To do so, I use the following configuration :
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-keep, allowobfuscation class com.company.*
-keepclassmembers, allowobfuscation class * {
*;
}
-keepnames class com.company.MyClass { *; }
-keepclassmembernames class com.company.MyClass {
public <methods>;
public <fields>;
#!private *; also tried this but it didn't work
}
However my private classes names and attributes still have the same name even though the content is obfuscated. Did I miss something in my wildcards?
After playing a bit, I found the following to be working
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-keep, allowobfuscation class com.company.*
-keepclassmembers, allowobfuscation class * {
*;
}
-keepnames class com.company.MyClass
-keepclassmembernames class com.company.MyClass {
public <methods>;
public <fields>;
#!private *; also tried this but it didn't work
}
The error in your configuration is the presence of { *; }
at the end of the -keepnames
option.
I used the following class:
package com.company;
public class MyClass {
public static void main(String[] args) {
int longVariableName = publicStaticMethod();
String abcxyz = privateStaticMethod("abc", "xyz");
System.out.println("longVariableName: " + longVariableName);
System.out.println("abcxyz: " + abcxyz);
}
public static int publicStaticMethod() {
return 9000;
}
private static String privateStaticMethod(String first, String second) {
return first + second;
}
}
and the decompiled resulting class was this:
package com.company;
import java.io.PrintStream;
public class MyClass {
public static void main(String[] paramArrayOfString) {
paramArrayOfString = publicStaticMethod();
String str = a("abc", "xyz");
System.out.println("longVariableName: " + paramArrayOfString);
System.out.println("abcxyz: " + str);
}
public static int publicStaticMethod() {
return 9000;
}
private static String a(String paramString1, String paramString2) {
return paramString1 + paramString2;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With