代码之家  ›  专栏  ›  技术社区  ›  Nivrutti Pawar

如何使用proguard牙签规则?

  •  3
  • Nivrutti Pawar  · 技术社区  · 7 年前

    我正在我的项目中使用TP。
    我正在使用TP注入一些对象。但是当我在应用程序中应用proguard规则时。它在调试模式下工作正常,但在发布模式下为null对象提供我通过@Inject注释注入的所有对象。

    1 回复  |  直到 7 年前
        1
  •  2
  •   kingargyle    7 年前

    我在我们的项目中有这项工作,除了问题#146之外,你还需要补充一些东西。android support annotations库中有一个@Keep注释设置,可以用来标记一个不需要模糊处理的类,我不得不在一些kotlin数据类上做这件事作为改装,kotlin reflect库无法很好地处理模糊处理。无论如何,可以找到要点 here . 此外,您可能希望明确告诉它不要混淆您告诉Toothick生成非反射注册表和工厂实现的包中生成的FactoryRegistry类中的任何内容。

        # Note that if we could use kapt to generate registries, possible to get rid of this
    -keepattributes Annotation
    # Do not obfuscate classes with Injected Constructors
    -keepclasseswithmembernames class * {
        @javax.inject.Inject (...);
    }
    # Do not obfuscate classes with Injected Fields
    -keepclasseswithmembernames class * {
        @javax.inject.Inject ;
    }
    # Do not obfuscate classes with Injected Methods
    -keepclasseswithmembernames class * {
        @javax.inject.Inject ;
    }
    -keep @android.support.annotation.Keep class *
    -keep @javax.inject.Singleton class *
    -dontwarn javax.inject.**
    -dontwarn javax.annotation.**
    -keep class **$$Factory { *; }
    -keep class **$$MemberInjector { *; }
    
    -adaptclassstrings
    -keep class toothpick.** { *; }