16

I am trying to prevent proguard from obfuscating interface (or abstract class) methods parameters.

Lets say I have this interface in my lib :

package com.mypackage;
public interface MyLibListener {
    void onSomething(boolean success, String message); 
}

And this proguard file :

-keepparameternames
-keep interface com.mypackage.MyLibListener {
    *;
}

Then I assemble release and I get :

package com.mypackage;
public interface MyLibListener {
    void onSomething(boolean var1, String var2);
}

Same thing with abstract classes or using @Keep annotations. Obfuscation option keepparameternames seems to work only for regular classes. Any idea? Thanks!

(related SO : How to not obfuscate interface methods & it's parameters using Progaurd in android? and Proguard keep interface method variable names)

Community
  • 1
  • 1
frouo
  • 5,087
  • 3
  • 26
  • 29

3 Answers3

9

Add following ProGuard options to your configuration.

-keepattributes MethodParameters

If your class file hava method parameters metadata (compiled using Java8 -parameters or etc...)`, ProGuard will keep the metadata.

Beck Yang
  • 3,004
  • 2
  • 21
  • 26
2

To keep all interface methods:

-keep interface * {
   <methods>;
}

To keep all public and protected methods, which could be used by reflection:

-keepclassmembernames class * {
    public protected <methods>;
}

While I don't understand, why one would want to keep abstract classes, which cannot be instanced anyway, therefore it's pointless to keep & know their names. In theory, one could exclude all that is not abstract with rules which start with -keep !abstract, but that's kind of redundant.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
-3

Your proguard file may lack some -keepattributes, especially a -keepattributes Signature.

Check this example proguard configuration for a library from the proguard documentation to look for ideas.

ldavin
  • 423
  • 2
  • 5
  • 16