避免混淆R8:内部类或接口,外部类在其中扩展或实现

时间:2020-08-04 13:27:16

标签: proguard obfuscation android-r8

如果要保留内部类,请使用-keep public class com.example.MyClass$MyInnerClass { *; }(或-keep public class com.example.MyClass$* { *; }保留任何多个内部类)。

问题:是否可以保留一个类的所有内部类,这些内部类通过扩展或实现来匹配签名?

interface MyInterface { fun foo() }
class Foo : MyInterface {
  override fun foo() {}
  class Inner    // <- keep these with one rule for all `MyInterface` implementations
  class Another  // <- keep these with one rule for all `MyInterface` implementations
}
class Bar : MyInterface {
  override fun foo() {}
  class Third    // <- keep these with one rule for all `MyInterface` implementations
  class Fourth   // <- keep these with one rule for all `MyInterface` implementations
}

类似-keep public class (com.example.** implements io.foo.bar.MyInterface)$*

1 个答案:

答案 0 :(得分:1)

您应该能够使用以下条件保留规则:

-if class com.example.** implements io.foo.bar.MyInterface
-keep class com.example.<1>$*

如果软件包com.example中的类实现了io.foo.bar.MyInterface,请保留其所有内部类。