Android proguard, keep inner class of Inner class

耗尽温柔 提交于 2020-02-28 07:35:33

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/39653725/android-proguard-keep-inner-class-of-inner-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!