androidkotlinkotlin-multiplatform

Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/serialization/internal/EnumsKt;


We are using a 3rd party library whose code is based on kotlin multiplatform and our project has a Groovy DSL. When I added the library and calls their methods my app is crashing. How can I fix the same. Please see the image of the crashlog received in firebase crashlytics. I am not sure if it is issue from our code or from 3rd party library. Can anyone help us hereenter image description here


Solution

  • The two steps for adding support for kotlinx serialization:

    1) Add Gradle plugin

    Groovy DSL:

    plugins {
        id 'org.jetbrains.kotlin.multiplatform' version '2.0.0'
        id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.0'
    }
    

    2) Add library dependency

    Groovy DSL:

    repositories {
        mavenCentral()
    }
    
    
    commonMain {
        dependencies {
            implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.1"
            implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1"
        }
    }
    
    

    Reference:

    https://github.com/Kotlin/kotlinx.serialization?tab=readme-ov-file#gradle