3

How to avoid the following method name from obfuscation?

public static void testClassMethod(String testVaiable1,Stringtestvariable2) {
    System.out.println( testVaiable1);
}

but after obfuscating my method was

TestClass.testClassMethod(s:"abc", s1:"pqr");

my proguard file contains the following rules

-keep class com.example.mylibrary.TestClass**
-keepclassmembers class com.example.mylibrary.TestClass** 
 {*;}
-keep class com.example.mylibrary.TestClass{
    public void 
        testClassMethod(java.lang.String,java.lang.String);
}
Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27

2 Answers2

1

Try this

-keepnames class com.yourPackage.TestClass
-keepclassmembernames class com.yourPackage.TestClass {
    public <methods>;
    public <fields>;
    #!private *; 
}

edit Try this:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-keep, allowobfuscation class com.YOURPACKAGE.*
-keepclassmembers, allowobfuscation class * {
    *;
}

-keepnames class com.YOURPACKAGE.YOURCLASS
-keepclassmembernames class com.YOURPACKAGE.YOURCLASS {
    public <methods>;
    public <fields>;
    #!private *;
}
Blnpwr
  • 1,793
  • 4
  • 22
  • 43
  • Did you replace "yourPackage"? – Blnpwr Aug 27 '19 at 13:25
  • yes. -keepnames class com.example.mylibrary.TestClass -keepclassmembernames class com.example.mylibrary.TestClass { public ; public ; #!private *; } – sonali parab Aug 27 '19 at 13:28
  • Are you sure you did not miss anything? Because for my test class everything works. What is your gradle version? – Blnpwr Aug 27 '19 at 13:54
  • -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -keep, allowobfuscation class com.example.mylibrary.* -keepclassmembers, allowobfuscation class * { *; } -keepnames class com.example.mylibrary.TestClass -keepclassmembernames class com.example.mylibrary.TestClass { public ; public ; #!private *; } – sonali parab Aug 27 '19 at 13:57
  • my Gradle version is 5.1.1 – sonali parab Aug 27 '19 at 13:57
0

update android studio and added the following two lines into proguard file

  -keep class com.example.mylibrary.TestClass{*;} - 
   keepparameternames 

The above solution works for me.