Android proguard,保持内部类的内部类 [英] Android proguard, keep inner class of Inner class

查看:478
本文介绍了Android proguard,保持内部类的内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

父级问题: Android proguard,保持内部类

我的问题是内部类的内部类

其中一个SDK 有一个类A,该类具有两个静态内部类.发现在使用了proguard后它们被剥夺了.

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{
    ...
  }
}

我的护卫看起来像这样

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

这阻止了B,C类的保护.但是D类没有运气.我也尝试过-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.

推荐答案

我认为您缺少ProGuard中显示的Class规范

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

尝试更换:

-keep class com.xxx.A

使用:

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

我正在将以下规则与以下文件一起使用,并且在带有构建工具25.0.1的Android Studio 2.2.3上可以正常使用(以防万一它们可能会影响所使用的ProGuard版本)

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.

如果这不起作用

您始终可以使用不带通配符的规则.以下将解决问题:

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

-keep class com.xxx.A$B$D

这篇关于Android proguard,保持内部类的内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆