https://kotlinlang.org logo
#android
Title
# android
s

sewon

01/29/2019, 8:38 AM
I used kotlin lazy property in serializeable class. It works well in debug mode build, but crashed in release build (with proguard). I've solve this issue by adding below rule to proguard settings.
Copy code
-keepclassmembers class * {
 *** writeReplace();
}
androdi application code: https://gist.github.com/kingori/518e8afcb6fb4d90b81eb8348395f39e post on this issue( in Korean) : https://steemit.com/kotlin/@kingori2/kotlin-lazy-field-serialize-proguard
g

gildor

01/29/2019, 8:40 AM
Maybe better exclude lazy property from serilization (add
@Transient
annotation)
s

sewon

01/29/2019, 8:43 AM
@gildor Yes, I agree. It can help avoid that problem. But every developers should keep that in mind, so that problem could be potential source of error.
g

gildor

01/29/2019, 8:44 AM
Yes, and the main source of those problems is
java.io.Serializable
which should be used really carefully
👍 1
kotlin delegate is not something unique, you have all those problems in many other cases if you just add Serializable to class
s

sewon

01/29/2019, 8:47 AM
Yes.
Parcelable
could be another good solution. I think it does not have all these kind of problems.
g

gildor

01/29/2019, 8:49 AM
At least Parcelable is very explicit about implementation, doesn’t work with Serializable magic
also should be faster
5 Views