Describe the bug
To Reproduce
Attach a code snippet or test data if possible.
Having a data class JwtResult
@Keep
@Serializable
data class JwtResult(
val nonce: String,
val ctsProfileMatch: Boolean,
val basicIntegrity: Boolean
)
and trying to parse the Json to JwtResult.class by
val returnedPayload = Json { ignoreUnknownKeys = true }.decodeFromString<JwtResult>(decodedPayload)
Exception was thrown in release build (minifyEnabled), but not debug build.
Seem the class was gone during the build process.
Serializer for class 'JwtResult' is not found. Mark the class as @Serializable or provide the serializer explicitly.
kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered
Expected behavior
successfully parsing the JSON
Environment
Try this:
val returnedPayload = Json { ignoreUnknownKeys = true }.decodeFromString(JwtResult.serializer(), decodedPayload)
This seems to be a proguard configuration problem. The suggested solution should fix it as it certainly makes a static reference to the serializer. However decodeFromString should be inline reified and do this too.
Yes. I believe it is an issue from R8.
Stumbled upon this one as well. Downgraded the version to 1.0.0-RC (was RC2) and the issue disappeared.
It seems to be an Android issue. Could you please provide a reproducing project with your R8 configuration?
🤦♂️ It is fixed by adding the following the instruction about proguard from readme.md
I was expecting the @Keep annotation will handle this well.
-keepattributes Annotation, InnerClasses
-dontnote kotlinx.serialization.SerializationKt
-keep,includedescriptorclasses class com.yourcompany.yourpackage.$$serializer { ; } # <-- change package name to your app's
-keepclassmembers class com.yourcompany.yourpackage. { # <-- change package name to your app's
Companion;
}
-keepclasseswithmembers class com.yourcompany.yourpackage. { # <-- change package name to your app's
kotlinx.serialization.KSerializer serializer(...);
}
I had same issue that yours! Serializables data clases seemed dissapear only during build release and I got the same error.
In my case, I just added Keep anotation and try with @Arutyun2312 static serializer solution. It works perfectly!!!
Thank you very much for open this issue!! :)
Note, you will get this error if you have not added serializations to your gradle plugins section:
plugins {
kotlin("plugin.serialization") version "1.4.31"
}
I assume this can be closed now
Most helpful comment
🤦♂️ It is fixed by adding the following the instruction about proguard from readme.md
I was expecting the
@Keepannotation will handle this well.