最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

android - Is there anything to do in proguard while using kotlinx serialization? - Stack Overflow

matteradmin5PV0评论

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?

Post a comment

comment list (0)

  1. No comments so far