Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android proguard, keep inner class of Inner class

Parent question: Android proguard, keep inner class

My problem is with inner class of inner class

One of the SDKs in my android project has a class A, which has two static inner class. They are found to be stripped after applying proguard.

public class A{
  ....

  static class B{
    ...
    static class D {
        ....
    }

  }

  static class C{
    ...
  }
}

My proguard looks like this

-keepattributes Exceptions, InnerClasses
-keep class com.xxx.A
-keep class com.xxx.A$*

Which prevents class B, C from proguard. But no luck with class D. I have tried -keep class com.xxx.A$** as well.

like image 848
Mahendran Avatar asked Nov 08 '22 08:11

Mahendran


1 Answers

I think you're missing the Class specification as shown in the ProGuard manual.

Try replacing:

-keep class com.xxx.A

With:

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

I'm using that rule with the following file and it's working fine on Android Studio 2.2.3 with build tools 25.0.1 (just in case those might affect the version of ProGuard being used)

A.java

package com.xxx;

public class A {
  ....

  public class B {
    ....

    public class C {
    ....
    }
  }
}

As you can see the only real difference between my file and yours is that my inner classes are public and non-static.

If that doesn't work

You can always use a rule without wildcards. The following will do the trick:

-keep class com.xxx.A$B$D
like image 129
Nicolás Carrasco-Stevenson Avatar answered Nov 14 '22 22:11

Nicolás Carrasco-Stevenson