29

Lets say I have..

public class SomeClass {


    public interface someInterface {

        public void firstMethod(String variable);


        public void secondMethod(String variable);


        public void thirdMethod();

    }
}

and I do..

-keep,includedescriptorclasses public class com.somepackage.SomeClass {
    <fields>;
    <methods>;
}

-keep public interface com.somepackage.someInterface {*;}

I end up with

public interface someInterface {

        public void a(String variable);


        public void a(String variable);


        public void a();

    }

How do I ensure this interface's method names are not obfuscated while still obfuscating the rest of the class?

Vic Vuci
  • 6,993
  • 6
  • 55
  • 90
  • If its inside of a class, shouldn't the proguard parameters include your outer class as part of the full name of the interface? – Morrison Chang Sep 04 '14 at 16:50

3 Answers3

44

ProGuard uses the naming convention of Java bytecode, as seen in class file names and stacktraces. Therefore:

-keep public interface com.somepackage.SomeClass$someInterface {*;}
Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • 5
    I lost an hour because I used above syntax which didn't work for me. The reason was that I define my interfaces without the public accessor (it's obsolete since all interfaces are public). In that case you need to use: -keep interface com.somepackage.SomeClass$someInterface {*;}. I think ProGuard should be "clever" enough to handle his case automatically. – Emanuel Moecklin Jan 30 '17 at 21:18
2

I tried the following and it seemed to work:

-keep interface com.somepackage.SomeClass$someInterface
Phileo99
  • 5,581
  • 2
  • 46
  • 54
1

For those who are looking for how to keep a custom annotation (which is defined in a @interface in java) retaining its all members,

you should actually use like below to keep it:

-keep @interface com.your.annotation.interface. {*;}
Meraj al Maksud
  • 1,528
  • 2
  • 22
  • 36
SebastianX
  • 142
  • 1
  • 5
  • isnt that you should have it like -keep @interface com.your.annotation.interface.** { *; } or it is the different meaning? – Emil Jul 10 '22 at 23:15