I am using Kotlinx serialization in my KMP project.
This is the plugins section of the build.gradle file for shared module:
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.ksp)
alias(libs.plugins.room)
alias(libs.plugins.skie)
kotlin("plugin.serialization") version "2.0.20"
}
This is the gradle file for my androidApp:
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.pluginsposepiler)
id("kotlin-parcelize")
kotlin("plugin.serialization") version "2.0.20"
}
This is my project level gradle file:
plugins {
//trick: for the same plugin versions in all sub-modules
alias(libs.plugins.androidApplication).apply(false)
alias(libs.plugins.androidLibrary).apply(false)
alias(libs.plugins.kotlinAndroid).apply(false)
alias(libs.plugins.kotlinMultiplatform).apply(false)
alias(libs.pluginsposepiler).apply(false)
kotlin("plugin.serialization") version "2.0.20"
}
When I run the app with minifyEnabled, I get this exception:
F4.h: Serializer for class 'a' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
As per the offical docs (.serialization), it says that nothing has to be added in proguard.
However, only when I add
-keep @kotlinx.serialization.Serializable class * {*;}
am I able to run the project with minifyEnabled true.
Why does the behavior seem different from what the docs say?