我正在构建一个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 }
但是,即使内容被混淆,我的私有类名称和属性仍然具有相同的名称。我是否遗漏了通配符中的内容?
玩了一段时间后,我发现以下内容有效
-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选项末尾存在。
{ *; }
-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; } }