使用ProGuard的java.util.Date为null



项目:https://github.com/dakshj/TMDb_Sample

当我在Development_Debug Build Flavor中运行应用程序时电影.java返回一个非null的Date对象,从而使用DataBinding对其进行处理在这里工作良好。TextView中填充了一个格式化的日期字符串。

然而,当我在Development_Release Build Flavor with minifyEnabled true中使用完全相同的代码运行应用程序时,该应用程序与具有以下堆栈跟踪的NullPointerException一起崩溃:

FATAL EXCEPTION: main
Process: com.daksh.tmdbsample, PID: 10470
Theme: themes:{default=overlay:com.baranovgroup.nstyle, iconPack:com.baranovgroup.nstyle, fontPkg:com.baranovgroup.nstyle, com.android.systemui=overlay:com.baranovgroup.nstyle, com.android.systemui.navbar=overlay:com.baranovgroup.nstyle}
java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference
    at java.util.Calendar.setTime(Calendar.java:1197)
    at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:527)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:829)
    at java.text.DateFormat.format(DateFormat.java:314)
    at com.daksh.tmdbsample.data.model.Movie.a(Unknown Source)
    at com.daksh.tmdbsample.databinding.MovieDetailBinding.b(Unknown Source)
    at android.databinding.ViewDataBinding.a(Unknown Source)
    at android.databinding.ViewDataBinding$6.run(Unknown Source)
    at android.databinding.ViewDataBinding$5.onViewAttachedToWindow(Unknown Source)
    at android.view.View.dispatchAttachedToWindow(View.java:14535)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2836)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1115)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6023)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    at android.view.Choreographer.doFrame(Choreographer.java:606)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

此外,当我将-dontobfuscate规则添加到proguard-rules.pro.

请帮助我解决此崩溃(我不想将-dontobfuscate添加到我的ProGuard规则中(。

我应该添加哪些ProGuard规则?可能是Gson和java.util.Date的东西?

显然,Movie.java中的语法糖停止工作:

@BindingAdapter({"releaseDate"})

你要么需要重写代码,要么在proguard中为这个类做一个异常。

您正在为被混淆的字段(releaseDate(使用BindingAdapter。这将不起作用,您需要保持此字段不混淆。我的建议是添加以下内容:

-keep class com.daksh.tmdbsample.data.model.Movie {
    private final java.util.Date releaseDate;
}

如果你有更多的情况需要保持字段名称不模糊,我建议使用注释来保持这样的字段,并使用这样的规则(假设你在它们上使用@SerializedName注释(:

-keepclassmembers class * {
    @com.google.gson.annotations.SerializedName <fields>;
}

相关内容

  • 没有找到相关文章

最新更新