16

I'm using ProGuard in AndroidStudio 1.2.1.1 with Gradle 1.2.3.

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.

Here is my proguard config file (after many tries) as of now:

-allowaccessmodification
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-verbose
[...]

But I end up, after decompiling with androdd from AndroidGuard, with:

private com.google.android.gms.common.api.GoogleApiClient googleApiClient;

I know the use of this obfuscation is limited, but I would like googleApiClient to be renamed by ProGuard. How to do so?

Here is the refcard.

Is there any way to do the opposite of -keepclassmembernames?

2
  • is googleApiClient the only unobfuscated field or is it the same for all fields? Jun 1, 2015 at 14:25
  • 1
    I would like this for all private fields. Jun 1, 2015 at 14:53

1 Answer 1

12
+50

Getting from this: How to tell ProGuard to keep private fields without specifying each field

According to ProGuard documenation the wildcard matches any field.

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.
}
3
  • I used -keepclassmembers class my.package { !private <fields>; protected <field>; public <fields>; <methods>; } and got what I wanted: fields with names a, b, c etc. I knew this has to do with negators, thanks for leading me to the right usage. I will refine for my personal usage, but that is the answer I was looking for. Jun 8, 2015 at 9:30
  • Here is my final ProGuard file that works bug Android bug #78377: gist.github.com/shkschneider/a1c81780cd1f35a7037d Jun 8, 2015 at 9:55
  • Thank you for your response and for the reward! I am glad that you worked out based on my hints, also thanks for putting to github, it was a good experience for me also.
    – czupe
    Jun 9, 2015 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.