1

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.plugins.compose.compiler)
    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.plugins.compose.compiler).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 (https://github.com/Kotlin/kotlinx.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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.