带有ProGuard的java.util.Date null

时间:2016-09-11 08:17:26

标签: java android gson proguard java.util.date

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

当我在ntohs(addr->sin_port) Build Flavor中运行应用程序时,该模型 Movie.java 返回一个非null的Date对象,因此使用Development_Debug进行处理 here 工作良好。 DataBinding填充了格式化的日期字符串。

但是,当我使用与minifyEnabled true TextView Build Flavor完全相同的代码运行应用时, 应用程序崩溃,Development_Release包含以下堆栈跟踪:

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的东西?

2 个答案:

答案 0 :(得分:0)

显然Movie.java中的这个句法糖停止了工作:

@BindingAdapter({"releaseDate"})

你需要重写代码或在proguard中为这个类做一个例外。

答案 1 :(得分:0)

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

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

如果你有更多需要保持字段名称不被混淆的情况,我建议使用注释来保持这样的字段具有这样的规则(假设你对它们使用@SerializedName注释):

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