I'm trying to migrate from ThreeTen Android Backport to java.time with desugaring. On debug builds this works perfectly, but on release builds (minifyEnabled = true
) I get a weird error on runtime.
After a ZonedDateTime is serialized (passing a Bundle in an Intent), the ZonedDateTime is lacking the TimeOffset:
before: 2022-06-07T02:00+02:00
after: 2022-06-07T02:00null
I'm using gradle version 7.2.1 (AGP 7.3.3) in combination with the basic backup from the android docs listed above. (changing it to java 11 does not fix the problem)
android {
...
compileOptions {
// Flag to enable support for the new language APIs (java.time)
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
...
}
dependencies {
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
}
Do I miss any configuration (e.g. in proguard-rules)? How can I fix this issue?
UPDATE 1: 09.06.2022
Here is a minimal reproducable example of the problem. Keep in mind that this only happens with minifyEnabled = true
val zonedDateTime = ZonedDateTime.parse("2022-06-07T02:00:00.000+02:00", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSVV"))
// zonedDateTime.toString() == "2022-06-07T02:00+02:00"
val bundle = Bundle()
bundle.putSerializable("date", zonedDateTime)
bundle.getSerializable("date") // .toString() == "2022-06-07T02:00null"
The general issue was that the desugar_jdk_libs "did not support Serialization with the default java serializer in desugared library besides collections".
This issue is resolved in version 1.1.6 of the library:
Now everything wokrs as expected when minify is enabled!