Released APK crashes with next error:
Serializer for class 'User' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
@Keep
@Serializable
data class User(
val id: Long = 0,
val name: String? = null,
val token: String? = null
)
@ExperimentalSerializationApi
object UserSerializer : Serializer<User> {
override val defaultValue: User
get() = User()
override suspend fun readFrom(input: InputStream): User {
return ProtoBuf.decodeFromByteArray(input.readBytes())
}
override suspend fun writeTo(t: User, output: OutputStream) {
output.write(ProtoBuf.encodeToByteArray(t))
}
}
I added official proguard rules from
https://github.com/Kotlin/kotlinx.serialization#android
(with my package of course)
Even added @Keep
to User
class but still it crashes
What is the problem here?
UPDATE
Found the issue. I actually had one companion object inside User
and had to add @Keep for this one as well to fix the issue:
@Keep
@Serializable
data class User(
val id: Long = 0,
val name: String? = null,
val token: String? = null,
...
) {
@Keep
companion object {
const val ...
...
}
}