Hey folks - hitting a weird runtime crash in a KMP...
# compose
s
Hey folks - hitting a weird runtime crash in a KMP project and wondering if anyone's seen this before. Getting
IncompatibleClassChangeError
on
$stable
when
kotlinx-serialisation
tries to deserialize plain DTO classes at runtime:
Copy code
java.lang.IncompatibleClassChangeError:
Expected 'int food.boo.bar.data.remote.dto.CategoryDto.$stable'
to be a instance field rather than a static field
  at CategoryRepository.getCategories(CategoryRepository.kt:47)
The offending class is completely vanilla — no Compose annotations, no custom serializers:
Copy code
@Serializable
data class CategoryDto(
    val id: Int,
    val name: String
)
Reproduces across three different toolchain combos:
Copy code
Kotlin 2.4.0-Beta2 + Compose MP 1.10.3 + KSP 2.3.7
Kotlin 2.3.21    + Compose MP 1.10.3 + KSP 2.3.7
Kotlin 2.3.10    + Compose MP 1.10.1 + KSP 2.3.6
Other context: • This is a debug build — no R8, minification is disabled, so it's not a shrinking artifact • The Compose compiler plugin is applied to the whole app module with no stability configuration, so it's instrumenting every class in commonMain, including these plain DTOs • The crash only fires during deserialization (construction via the serialization-generated factory), not when constructing the DTO manually Is this a known interaction between the Compose compiler plugin and the
kotlinx-serialization
plugin's generated constructor code? Any idea what changed recently that could cause $stable to land as a static field when the serialization-generated init path runs? Happy to file a YouTrack issue with a reproducer if helpful.
a
Ah, I've just filed a bug report for it! See https://youtrack.jetbrains.com/issue/KT-85963
s
😭 its blocking my release really bad
a
It doesn't happen on versions prior to 2.4.0-Beta2 on my end, though
s
lme try that again i recently switching to SPM from cocoapods thats why i bumped the kotlin version
a
Try to see if applying the serialization plugin before the compose one changes anything
Copy code
plugins {
  […]
  alias(libs.plugins.kotlinSerialization) 
  alias(libs.plugins.composeCompiler)
}
👀 1
s
trying that out
That fixed it! 🎉 Swapped
kotlinSerialization
to apply before
composeCompiler
in the
plugins {}
block of my
composeApp/build.gradle.kts
, did a clean install, and the
IncompatibleClassChangeError
Confirming on Kotlin 2.3.21 + Compose MP 1.10.3 + KSP 2.3.7 @Asapha thanks, god may bless you
🎉 2