使用ProGuard混淆私有字段 [英] Obfuscate private fields using ProGuard
问题描述
我在AndroidStudio 1.2.1.1中使用ProGuard和Gradle 1.2.3。
I'm using ProGuard in AndroidStudio 1.2.1.1 with Gradle 1.2.3.
My Gradle的发布版本配置如下:
My Gradle's release build is configured like so:
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
我希望对类的私有字段进行模糊处理。
I would like the private fields of classes to be obfuscated.
这是我的proguard配置文件(经过多次尝试)截至目前:
Here is my proguard config file (after many tries) as of now:
-allowaccessmodification
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-verbose
[...]
但是我在从AndroidGuard反编译 androdd
后结束了with:
But I end up, after decompiling with androdd
from AndroidGuard, with:
private com.google.android.gms.common.api.GoogleApiClient googleApiClient;
我知道这种混淆的使用是有限的,但我希望 googleApiClient
由ProGuard重命名。怎么做?
I know the use of this obfuscation is limited, but I would like googleApiClient
to be renamed by ProGuard. How to do so?
这是 refcard 。
有没有办法与 -keepclassmembernames
相反?
推荐答案
从中得到:
如何告诉ProGuard保留私有字段而不指定每个字段
根据 ProGuard文档,通配符匹配任何
字段。
According to ProGuard documenation the wildcard matches any field.
最重要的是,你可以使用否定符(!)。
( http://proguard.sourceforge.net/#manual/usage.html )
Top of that, You can use negators (!). (http://proguard.sourceforge.net/#manual/usage.html)
属性名称可以包含?,*和**通配符,它们可以是
,前面是
的!否定。
Attribute names can contain ?, *, and ** wildcards, and they can be preceded by the ! negator.
我在这个领域并不是那么有经验,所以这是一个猜测,但更容易在新评论中写。这样的事情应该完成工作(没有测试):
I am not so experienced in this field, so rather it is a guess, but easier to write in a new comment. Something like this should do the job (NOT TESTED):
-keepclassmembers class * { //should find all classes
!private <fields>;
<methods>;
<init>; //and keep every field, method, constructor apart from private fields
}
可能是你可以这样使用,但不确定它是如何与否定器一起工作的:
May be you can use like this, but do not sure how it works with a negator first:
-keepclassmembers class * { //should find all classes
!private <fields>;
*; //should exclude everything except private fields, which should be obfuscated.
}
这篇关于使用ProGuard混淆私有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!