[英]Using joda-time-android with proguard
I'm trying to use joda-time-android in my app while also using proguard. 我正在尝试在我的应用程序中使用joda-time-android ,同时也使用proguard。 The problem is that when I try to get a LocalDate as from an Intent like this:
问题是,当我尝试从Intent获取LocalDate时,如下所示:
LocalDate date = (LocalDate) data.getSerializableExtra("dueDate");
I get this error: 我收到此错误:
Process: org.mpardalos.homeworkmanager, PID: 7509
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { (has extras) }} to activity {org.mpardalos.homeworkmanager/org.mpardalos.homeworkmanager.TaskList}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3389)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3432)
at android.app.ActivityThread.access$1300(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1253)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.joda.time.LocalDate.isSupported(LocalDate.java:577)
at org.joda.time.format.DateTimeFormatterBuilder$PaddedNumber.printTo(DateTimeFormatterBuilder.java:1434)
at org.joda.time.format.DateTimeFormatterBuilder$Composite.printTo(DateTimeFormatterBuilder.java:2446)
at org.joda.time.format.DateTimeFormatter.print(DateTimeFormatter.java:663)
at org.joda.time.base.AbstractPartial.toString(AbstractPartial.java:412)
at org.mpardalos.homeworkmanager.TaskList.onActivityResult(TaskList.java:91)
at android.app.Activity.dispatchActivityResult(Activity.java:5423)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3385)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3432)
at android.app.ActivityThread.access$1300(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1253)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
and the debugger says this about the variable: 并且调试器对变量说了这个:
Method threw 'java.lang.NullPointerException' exception.
However, the problem disappears as soon as I remove minifyEnabled
from the gradle build file. 但是,
minifyEnabled
从gradle构建文件中删除minifyEnabled
,问题就会消失。
The only temporary solution I've found is to disable proguard as the app is relatively small (2 MB without proguard - 0.9 MB with it) but I do plan to add a lot more functionality so I'm going to need it in the future. 我发现的唯一临时解决方案是禁用proguard,因为应用程序相对较小(2 MB没有proguard - 0.9 MB)但我确实计划添加更多功能,所以我将来需要它。
Could anyone point me to a solution for the problem? 有人能指出我解决问题的方法吗?
TL;DR joda-time-android doesn't work when proguard is enabled TL; DR joda-time-android在启用proguard时不起作用
For the v2.9.9 release version of joda-time-android , you don't need to add proguard rules. 对于joda-time-android的v2.9.9发行版,您不需要添加proguard规则。 This is because it already has contained the proguard with:
这是因为它已经包含了以下内容:
consumerProguardFiles 'proguard-rules.txt'
in its build.gradle. 在它的build.gradle中。
Please look at the source code: 请看一下源代码:
https://github.com/dlew/joda-time-android/blob/master/library/build.gradle https://github.com/dlew/joda-time-android/blob/master/library/build.gradle
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.