AnJ
AnJ

Reputation: 125

Android/Proguard - keep interface param names

I'm building an android library. I have an interface:

public interface MyInterface {
    public void onInitializationSuccess(MySession mySession, String name, String email);
    public void onInitializationFailure();
}

I have a proguard rule to keep MyInterface:

-keep public class com.package.name.MyInterface { *; }

When I try to implement this library in another project and create MyInterface this is how android studio creates it:

new MyInterface() {
        @Override
        public void onInitializationSuccess(MySession mySession, String s, String s1) {

        }

        @Override
        public void onInitializationFailure() {

        }
    }

I'm guessing 'mySession' name is kept because it's a custom class from the library (there's a proguard rule to keep it). I'd like to keep other two param names as well, so instead 's' and 's1' developer would see 'name' and 'email'. How can I do it without disabling proguard obfuscation for the whole project?

I know this question has been asked few times

here: Proguard keep interface method variable names

here: Proguard keep parameter names for interface and abstract class

and here: Proguard keep interface method paramternames

but the replies aren't really helpful.

Upvotes: 1

Views: 1495

Answers (1)

yeshu
yeshu

Reputation: 212

There is no way to specify in proguard to retain the parameter names of interfaces. This is limitation from javac. When javac generates .class files, it omits the parameter names. You can find more details about structure of .class files in the question here.

I am not sure if you know but the last link you provided has answer now(since the question was answered after you posted your question). Seems like there is a solution when using java 8.

Java 8 javac does this with -g and -parameters flags.

Upvotes: 2

Related Questions