After migrating from 0.8.1-rc13 to 0.8.2-rc13 compiling iOS project fails with the following error:
> Task :ios:compileDebugIos_arm64KotlinNative
common/src/main/kotlin/com/**/Foo.kt:159:76: error: unresolved reference: serializer
fun parse(jsonText: String): Foo = JSON.nonstrict.parse(serializer(), jsonText)
^
> Task :ios:compileDebugIos_arm64KotlinNative FAILED
Common and Android sub-projects build fine.
When I remove serializer() call to make it like this
fun parse(jsonText: String): Foo = JSON.nonstrict.parse(jsonText)
the iOS project builds, but I'm getting the same error at runtime I was getting earlier when not passing serializer as the first argument.
The error above occurs when using either ext.kotlin_version = '1.3.0-rc-131' or ext.kotlin_version = '1.3.0-rc-146'. My current list of dependencies is:
buildscript {
ext.kotlin_version = '1.3.0-rc-146'
ext.kotlinPluginUrl = "https://dl.bintray.com/kotlin/kotlin-eap"
ext.kotlinPluginClassPath = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
ext.kotlinNativeUrl = "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
ext.kotlin_native_version = '1.3.0-rc-146'
ext.kotlinNativeClassPath = "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
ext.serializationUrl = "https://kotlin.bintray.com/kotlinx"
ext.serialization_version = '0.8.2-rc13'
ext.serializationClasspath = "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
ext.android_gradle_version = '3.2.0'
ext.androidGradleClassPath = "com.android.tools.build:gradle:$android_gradle_version"
}
Any help would be greatly appreciated!
It looks like the plugin hasn't been applied to the compiler. Do you use kotlin-platform-native? How do you connect plugin with the compiler?
@sandwwraith
I do use 'kotlin-platform-native'
This is the top part of my iOS sub-projecct
buildscript {
repositories {
jcenter()
maven { url kotlinPluginUrl }
maven { url kotlinNativeUrl }
}
dependencies {
classpath kotlinPluginClassPath
classpath kotlinNativeClassPath
classpath serializationClasspath
}
}
apply plugin: 'kotlin-platform-native'
apply plugin: 'kotlinx-serialization'
repositories {
jcenter()
maven { url kotlinPluginUrl }
maven { url serializationUrl }
}
My top-level configuration that does not work with this iOS sub-project is in my original post
The top-level configuration that works with this iOS sub-project is this:
buildscript {
ext.kotlin_version = '1.3.0-rc-57'
ext.kotlinPluginUrl = "https://dl.bintray.com/kotlin/kotlin-eap"
ext.kotlinPluginClassPath = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
ext.kotlinNativeUrl = "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
ext.kotlin_native_version = '0.9.2'
ext.kotlinNativeClassPath = "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
ext.serializationUrl = "https://kotlin.bintray.com/kotlinx"
ext.serialization_version = '0.8.1-rc13'
ext.serializationClasspath = "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
ext.android_gradle_version = '3.2.0'
ext.androidGradleClassPath = "com.android.tools.build:gradle:$android_gradle_version"
}
For my working iOS sub-project I use mavenLocal() instead of maven { url serializationUrl }, and the commit that is used to publish serialization library locally is 7a7ebe94afdc930e751af9c095edb0c5fc8338a8 (to workaround the main thread related problem)
As soon as I switch to ext.serialization_version = '0.8.2-rc13', I get compiler version problem (either with maven { url serializationUrl } or with mavenLocal() in my iOS sub-project). But when I upgrade the kotlin_version to 1.3.0-rc-131 or 1.3.0-rc-146 I get this problem.
I'm not sure why the plugin hasn't been applied to the compiler. The only thing I did to run into the problem is to upgrade serialization to '0.8.2-rc13' and to bump up kotlin_version to 1.3.0-rc-146.
@sandwwraith
I created a test project that reproduces the problem, could you please take a look? The line that fails to compile is in Foo.kt
If you change the version information in gradle.properties to
kotlin_version=1.3.0-rc-57
kotlin_native_version=0.9.2
serialization_version=0.8.1-rc13
android_gradle_version=3.2.0
the compilation succeeds.
Please let me know if you need more information.
P.S. Reducing Foo to a bare minimum still reproduced the problem.
@sandwwraith Have you had a chance to look at the sample project?
@yuriry Yes, it reproduces the problem and I'm investigating it
It seems that the last release of Kotlin/Native gradle plugin for some reason does not add -XPlugin option to compiler. For a workaround, you can pass it manually, as here: https://github.com/sandwwraith/KotlinSerializationPlayground/blob/native_preview/native/build.gradle#L49
@sandwwraith Thank you for the workaround, it works!
Ok, so as explained in the linked issue, kotlin-platform-native now shades kotlin plugin inside, so all compiler plugins are also shaded and have different ids. To use the plugin with k/n 0.9.3 and library 0.8.2, use line apply plugin: 'kotlinx-serialization-native' in native modules. (this is applicable only to kotlin-platform-native, kotlin-multiplatform works as usual). I've updated the docs: https://github.com/Kotlin/kotlinx.serialization/commit/4ae3d34a05616d6542eca2b88afc7e30f9a0d9b6
I'm closing this now since it is a problem in K/N which has separate ticket.
Same question, but my project structure without build.gradle in ios project like https://github.com/JetBrains/kotlin-examples/tree/master/tutorials/mpp-iOS-Android
So, how I can pass -XPlugin for this situation ?
For kotlin-multiplatform plugin you can use usual apply plugin: 'kotlinx-serialization' line. Or do you experience another issue?
@tttzof351 Or maybe https://github.com/Kotlin/kotlinx.serialization/issues/264#issuecomment-439840968 would help you?