java 混淆私有属性方法,如何使用proguard混淆除公共方法名称和属性以外的所有内容?...

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:

keep all the classes included in the input jar, but obfuscate them.

don't obfuscate the class names of the classes called in the `AndroidManifest.xml

don't obfuscate the class name and public method names/attributes for the class that is used has an interface for the user, however do it for their contents.

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 ;

public ;

#!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 ;

public ;

#!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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值