Skip to content Skip to sidebar Skip to footer

How To Obfuscate Everything But Public Method Names And Attributes With 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 r

Solution 1:

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 <methods>;
    public <fields>;
    #!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;

publicclassMyClass {
  publicstaticvoidmain(String[] args) {
    int longVariableName = publicStaticMethod();
    String abcxyz = privateStaticMethod("abc", "xyz");
    System.out.println("longVariableName: " + longVariableName);
    System.out.println("abcxyz: " + abcxyz);
  }

  publicstatic int publicStaticMethod() {
    return9000;
  }

  privatestaticStringprivateStaticMethod(String first, String second) {
    return first + second;
  }
}

and the decompiled resulting class was this:

package com.company;

import java.io.PrintStream;

publicclassMyClass {
  publicstaticvoidmain(String[] paramArrayOfString) {
    paramArrayOfString = publicStaticMethod();
    String str = a("abc", "xyz");
    System.out.println("longVariableName: " + paramArrayOfString);
    System.out.println("abcxyz: " + str);
  }
  
  publicstatic int publicStaticMethod() {
    return9000;
  }
  
  privatestaticStringa(String paramString1, String paramString2) {
    return paramString1 + paramString2;
  }
}

Post a Comment for "How To Obfuscate Everything But Public Method Names And Attributes With Proguard?"