kotlinx.serialization: Android, Gradle, Serialization plugin is incompatible with Kotlin Android plugin 1.9.20
When choosing either
- the
1.9.20version of plugin"org.jetbrains.kotlin.android"or - the
1.9.20version of plugin"org.jetbrains.kotlin.plugin.serialization"or - both at the same time
the
@Serializable annotation on this simple class
@Serializable
data class SomeDataClass(val a: Int)
is highlighted with a warning:
"kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project."
To Reproduce
In other words, in the top-level build.gradle file, This setup leads to the error:
plugins {
id("com.android.application") version "8.2.0-rc01" apply false
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
id("com.google.devtools.ksp") version "1.9.20-1.0.14" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10" apply false
}
, and this setup leads to the error:
plugins {
id("com.android.application") version "8.2.0-rc01" apply false
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
id("com.google.devtools.ksp") version "1.9.20-1.0.14" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20" apply false
}
, and this setup leads to the error:
plugins {
id("com.android.application") version "8.2.0-rc01" apply false
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
id("com.google.devtools.ksp") version "1.9.20-1.0.14" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20" apply false
}
And this setup works as expected (at least there is no warning)
plugins {
id("com.android.application") version "8.2.0-rc01" apply false
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
id("com.google.devtools.ksp") version "1.9.20-1.0.14" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10" apply false
}
Notice how in the working example both "org.jetbrains.kotlin.android" and "org.jetbrains.kotlin.plugin.serialization" plugin versions are 1.9.10
Expected behavior There should be no error and the serialization plugin should be applied when using versions of it and Kotlin of 1.9.20
Environment
- Kotlin version: [1.9.20]
- Plugin version: [1.9.20]
- Kotlin platforms: [JVM]
- Gradle version: [8.2]
- IDE: Android Studio Hedgehog 2023.1.1 RC 3
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 45
- Comments: 33 (6 by maintainers)
Apparently, the issue is caused by a bug in the Kotlin 1.9.10 IDE plugin (not the Gradle plugin). It is described here: https://youtrack.jetbrains.com/issue/KTIJ-10755
To fix this problem, you need to update the Kotlin IDE plugin. Unfortunately, 1.9.20 IDE plugin version is not available for Hedgehog 2023.1.1 yet. There are two ways to fix it:
Settings -> Languages & Frameworks -> Kotlinor invoke actionConfigure Kotlin plugin updates. Select EAP channel in the window and update to 1.9.20-RC2 (per https://youtrack.jetbrains.com/issue/KTIJ-10755/HMPP-IDE-False-PLUGINISNOTENABLED-in-IDE-for-kotlinx-serialization-plugin-however-project-builds-correctly#focus=Comments-27-8389206.0-0)using 1.9.20 in Android Studio Hedgehog 2023.1.1 not work as well.
I can add it’s not only about annotation warning. Generated serializers are not resolved by the IDE (but code compiles).
@pdvrieze In my example I apply plugin like that
I think that’s the correct way to apply plugin when you want to share version across modules.
I’ve faced with the same problem, is there any solution?
@linean I’ve just tried you project. It does compile.
The annotation is still highlighted, the
.serializer()is unresolved.Running
maingives an errorBut a unit test with it has passed:
EDIT: after having launched the unit test the main function runs successfully for some reason.
Trying to open the project on Giraffe (2022.3.1 Patch 4) it indeed fails (LInux, so OS doesn’t seem to matter). I suspect this is a bug/incompatibility with older Intellij versions (the 2022.3.1 part of the Android Studio version). Note that the compiler plugin (and the corresponding IDE plugin) are managed through YouTrack.
Using 1.9.20-RC2 IDE Plugin in Android Studio Hedgehog breaks Jetpack Compose Live Edit feature
For me, using setting kotlin serialization to “1.6.2” fixed it after having enabled 1.9.20 EAP within Android Studio Hedgehog 2023.1.1
For me, Fixed when removed Retrofit converter API. Guess Retrofit Gson library was conflicted with kotlinxSerialization plugins
@lifestreamy Thank you!
kotlin.androidas1.9.10then removing `kotlin(“jvm”) did indeed work.Regarding
Just want to be 100% sure I understand your suggestion. Is it to add
kotlin("plugin.serialization") version "1.9.10" apply falseto the build.gradle.kts project then in the build.gradle.kts module add onlykotlin("plugin.serialization")? That does seem to work and appears much cleaner… Thank You!@Jdbarad
1.9.10versions of both plugins work correctly together without giving any warnings. You, of course, can downgrade to 1.9.0 or 1.3.0 or whatever though, it is your choice.Maybe the new releases with plugin versions 2.0.0+ will work as expected.
The current latest version for both plugins is
2.0.0-Beta1, I’ve not tested it.Not sure if this issue is awaiting more info, but even I started getting
kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project.warning for all
@Serializableannotations since upgradingkotlinx.serializationto1.6.1andkotlinto1.9.20.Although serialization does seem to work without problems.
You can find my project at https://github.com/ammargitham/WallFlow/, the dependency update commit is https://github.com/ammargitham/WallFlow/commit/8cbbe35c02f7afa6aeb23c417b814e14b14f54de.
Edit: I have tried out a bit more and I am also getting this with 1.9.0 and 1.9.10, so I guess this is not related to the original issue. My colleague pointed me to https://github.com/Kotlin/kotlinx.serialization/issues/2385#issuecomment-1764839583.
We are also facing this issue. AS Hedgehog 2023.1.1 RC 3, Kotlin/Serialization 1.9.20. The IDE is saying:
kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project.At runtime it only is a problem when using minification/proguard/r8 (setting: android.enableR8.fullMode = false). When trying to use
as request body in a Retrofit call, with r8 minification on, we are getting these exceptions: