android - 如何使用proguard牙签规则?

标签 android android-studio android-proguard sbt-proguard toothpick-di

我在我的项目中使用了 TP。
我正在使用 TP 注入(inject)一些对象。但是当我在我的应用程序中应用 proguard 规则时。它在 Debug模式下工作正常但是在 Release模式下为空对象提供我通过@Inject 注释注入(inject)的所有对象。

最佳答案

我在我们的项目中有这个工作,除了 Issue #146 中的内容之外,您需要添加更多内容。 android支持注解库中有一个@Keep注解设置,可用于标记一个类不被混淆,我不得不在一些kotlin数据类上这样做,因为Retrofit和kotlin-reflect库无法播放很好的混淆。无论如何,可以找到要点here .此外,您可能希望明确告诉它不要混淆您告诉 toothpick 生成非反射注册表和工厂实现的包中生成的 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.** { *; }

关于android - 如何使用proguard牙签规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47074752/

相关文章:

android - 检测程序焦点的变化

android - AChartEngine 和 Android Studio

android-studio - 文件菜单在 mac 上的 android-studio 上消失了

java - ProGuard 在具有 OpenCSV 依赖项的 Android 上构建失败

java - 在 Android 中实例化 172820 字符串数组的最佳方法是什么?

android - 需要在代码 list 中声明的​​权限

android - 在 Android 中防止来自 ListView 的重复图像字符串

java - Android studio 像这样设置布局

android - ProGuard 仍然显示完整的 Activity 名称

android - 无法使用 RxJava 作为依赖项和 proguard-rules 创建发布版本