Android kotlinx-serialization-json 1.9.0 library causes compile problems
11:40 05 Nov 2025

Background

My project so far has been going well. My next task is to add JSON serialization to my project. Here's the class I added:

@Serializable
data class SerializableChild(
    val rtype: String,
    val rid: String
)

Of course I have to add import statements too:

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json

And of course I have to tell build.gradle.kts about the new library

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")

Problem

After syncing, I now get all kinds of errors when compiling. The first (in MainActivity.kt) is:

import kotlin.math.roundToInt

Unresolved reference: roundToInt

which is really weird as math is a pretty well-established library, why can't the compiler find it?

The second error is more meaningful:

Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.2.0, but the compiler version 1.9.0 can read versions up to 2.0.0. The class is loaded from /Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.0/fdfc65fbc42fda253a26f61dac3c0aca335fae96/kotlin-stdlib-2.2.0.jar!/kotlin/Unit.class

Which to me is a head-scratcher. Not sure what this means. I've tried all the usual stuff, such as invalidate caches, restarting, updating everything in gradles and toml files, ran upgrade assistant, even switched to the latest version: Android Studio Otter | 2025.2.1. I also tried deleting the jar file specified in the second error (which is of course replaced by a new one during build). But this error still persists.

Here's a pic of my build window for those of you who are more visual: screen capture of issue

If I remove the library reference in build.gradle.kts and comment out all the serializable references the error goes away.

Anyone else experiencing this? Solutions?

json kotlin android-studio serialization libraries