我正在构建一个Android框架,我需要对jar进行模糊处理和缩小以将其发送给用户。
我使用android SDK中包含的proguard工具,我对输出jar有以下要求:
为此,我使用以下配置:
-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
}
但是,即使内容被混淆,我的私有类名称和属性仍然具有相同的名称。我在通配符中遗漏了什么吗?
答案 0 :(得分:8)
玩了一下之后,我发现以下内容正在发挥作用
-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
}
您的配置中的错误是{ *; }
选项末尾存在-keepnames
。
我使用了以下课程:
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;
}
}
和反编译的结果类是:
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;
}
}