After setting minifyEnabled true
in app build.gradle
script I starded to receive this exception:
Caused by: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = some.package.SomeClass)
at android.os.Parcel.writeSerializable(Parcel.java:1767)
…
Caused by: java.io.NotSerializableException: kotlin.UNINITIALIZED_VALUE
Crash occurred when I try to pass class SomeClass : Parcelable
to another activity.
I tried to whitelist all app classes with -keep class some.package.**.* { *; }
but without succeed.
I stumbled upon the same issue, and the current answer is wrong: adding @delegate:Transient
on the lazy will nullify the backing field on deserialization.
Since the issue is only occuring when minifyEnabled = true
, that's a Proguard/R8 issue. I solved it by adding the following lines to my proguard-rules.pro
:
-keep class * implements kotlin.Lazy {
*;
}