【问题标题】:Android proguard, keep inner class of Inner classAndroid proguard,保持Inner class的inner class
【发布时间】:2017-01-31 21:33:25
【问题描述】:

家长提问:Android proguard, keep inner class

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

我的 android 项目中的一个 SDK 有一个类 A,它有两个静态内部类。应用proguard后发现它们被剥离了。

public class A{
  ....

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

  }

  static class C{
    ...
  }
}

我的proguard是这样的

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

这会阻止 B、C 类的 proguard。但是 D 类没有运气。我也尝试过-keep class com.xxx.A$**。

【问题讨论】:

  • @TGMCians 不工作
  • 试试这个-keep class com.xxx.*$*
  • $ 也不起作用,但是 -dontwarn com.xxx.** 让我的构建成功。我想我应该稍后再做。
  • 您是否需要使用通配符的表达式,或者您会满足于只针对一个类的答案??

标签: java android android-proguard


【解决方案1】:

我认为您缺少 ProGuard manual 中显示的类规范。

尝试替换:

-keep class com.xxx.A

与:

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

我在以下文件中使用该规则,它在带有构建工具 25.0.1 的 Android Studio 2.2.3 上运行良好(以防这些可能影响正在使用的 ProGuard 版本)

A.java

package com.xxx;

public class A {
  ....

  public class B {
    ....

    public class C {
    ....
    }
  }
}

如您所见,我的文件和您的文件之间唯一真正的区别是我的内部类是公共的和非静态的。

如果这不起作用

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多