使用 Proguard 缩小时出现运行时问题

Runtime issues while using Proguard to minify

我的应用程序已完全准备好部署并且它使用了许多库。我想使用 Proguard 缩小代码,还想删除未使用的 类 和资源,但是在使用 Proguard 时出现运行时错误

java.lang.RuntimeException: Unable to create application com.rig.onblick.App: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference

我看了很多教程,但是编写 proguard 配置似乎太复杂了,因为我必须编写很多规则来确保我的应用程序 运行 完美。我从来没有在这种大项目中使用过proguard。任何人都可以告诉我最小的配置,它至少可以确保我的代码被缩小并且不会出现任何 运行time 错误。

我现在的配置如下

-dontwarn com.witt.mspapp.**

-keep class com.github.mikephil.** { *; }
-dontwarn com.github.mikephil.**

-keep class com.github.mikephil.** { *; }
-dontwarn org.apache.**

-keep class com.google.gms.** { *; }
-dontwarn com.google.gms.**

-keep class com.viewpagerindicator.** { *; }
-dontwarn com.viewpagerindicator.**

-keep class org.jivesoftware.smackx.** { *; }
-dontwarn org.jivesoftware.smackx.**

我正在调试环境中进行测试。我的gradle配置如下

debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

proguard 配置没有任何内容 "minimal configuration"。您将在他的官方回购页面上获得每个库的 proguard 配置。因此,无论您使用什么依赖项,都会通过这些依赖项并为每个依赖项添加 proguard 配置。