Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard keep parameter names for interface and abstract class

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)

like image 650
frouo Avatar asked Nov 21 '16 17:11

frouo


People also ask

What is consumerProguardFiles?

consumerProguardFiles 'consumer-rules.pro'} A consumer proguard rules file is like any other proguard rules files with the caveat that the rules inside it are automatically applied to the consuming application when the application is being built in a proguard enabled mode.

Does ProGuard remove unused classes?

Shrinking Options By default, ProGuard shrinks the code: it removes all unused classes and class members.

What is Dontwarn in ProGuard?

If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. ( http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)


1 Answers

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.

like image 120
Beck Yang Avatar answered Sep 18 '22 13:09

Beck Yang