Android proguard, keep inner class

My android program has a class A, which has two static inner class. They are found to be stripped from .dex after applying proguard.

public class A{

  ...
  static class B{
    ...
  }

  static class C{
    ...
  }
}

I have put the following lines in proguard.flags, but seem no luck.

-keep class com.xxx.A
-keep class com.xxx.A$*

Any hint?


Try adding InnerClasses to the keep attributes. e.g:

-keepattributes Exceptions, InnerClasses, ...

Also, try adding a body to the "keep" call with an asterisk, like so:

-keep class com.xxx.A$* {
    *;
}

This is what I had to do for my config

-keep class com.xxx.A { *; }
-keep class com.xxx.A$B { *; }
-keep class com.xxx.A$C { *; }

This did the trick for me

-keepattributes InnerClasses
 -keep class com.yourpackage.YourClass**
 -keepclassmembers class com.yourpackage.YourClass** {
    *;
 }

It may be a bit overkill with the wildcards but I wanted to make sure I didn't miss anything. The main thing is you need the InnerClasses attributes the keep on the class and the keepclassmembers on the class.


if you don't want all inner class and members in some package to be obfuscated you can add lines in proguard-rules.pro

    -keep class com.xxx.task.*$* {
        *;
    }