Hi Everyone. Getting a really odd error with Seria...
# multiplatform
s
Hi Everyone. Getting a really odd error with Serialization on Ktor. Some background. I'm building a networking library on Android / iOS and Web. Since library bundling was released in 1.3.70 I need to keep that version. There was an incompatibility between 1.3.70 and serialization runtime of 0.14.0. Bumping to 0.20.0 was supposed to sort this. I keep getting this error on android now.
Copy code
java.lang.NoSuchFieldError: No field Companion of type Lkotlinx/serialization/json/Json$Companion; in class Lkotlinx/serialization/json/Json; or its superclasses (declaration of 'kotlinx.serialization.json.Json' appears in /data/app/com.example.multi_lib_test-lN7jV2p0qEWG7bt14TsLGg==/base.apk)
I have cleaned all my caches on both the library creation project and the test project implementing the lib. My current libraries used are the following
Copy code
Android Gradle: 3.6.1 (Both Projects)
Gradle Verison: 6.2.1 (Both Projects)
Kotlin Version: 1.3.70 (Both Projects)
Ktor: 1.3.1 (Library Project)
Coroutines: 1.3.4 (Library Project)
Serialization: 0.20.0 (Library Project)
I have tried for over two days to make this work but it just seems to have the same issue. I can't go back to 1.3.61 due to JS.
This is my
build.gradle.kts
file from the Library Project.
Copy code
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.*

group = "org.example"
version = "1.0.1-SNAPSHOT"

plugins {
    id("maven-publish")
    id("com.android.library")
    id("org.jetbrains.kotlin.native.cocoapods")
    kotlin("multiplatform")
    kotlin("plugin.serialization") version Versions.kotlin
}

kotlin {
    /* Targets configuration omitted. 
    *  To find out how to configure the targets, please follow the link:
    *  <https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets> */

    js {
        browser {
            dceTask {
                keep("ktor-ktor-io.\$\$importsForInline\$\$.<http://ktor-ktor-io.io.ktor.utils.io|ktor-ktor-io.io.ktor.utils.io>")
                keep("multiplatform-lib")
            }
            webpackTask {
                mode = Mode.PRODUCTION
                sourceMaps = false
            }
        }
    }

    android {
        publishLibraryVariants("debug", "release")
    }

    sourceSets {

        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:${Versions.coroutinesCore}")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:${Versions.serializationCommon}")
                implementation("io.ktor:ktor-client-core:${Versions.ktor}")
                implementation("io.ktor:ktor-client-json:${Versions.ktor}")
                implementation("io.ktor:ktor-client-serialization:${Versions.ktor}")
            }
        }

        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }

        val jsMain by getting {
            dependencies {
                implementation(kotlin("stdlib-js"))
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Versions.coroutinesCore}")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.serializationCommon}")
                implementation("io.ktor:ktor-client-js:${Versions.ktor}")
                implementation("io.ktor:ktor-client-json-js:${Versions.ktor}")
                implementation("io.ktor:ktor-client-serialization-js:${Versions.ktor}")
                api(npm("text-encoding"))
                api(npm("bufferutil"))
                api(npm("utf-8-validate"))
                api(npm("abort-controller"))
                api(npm("fs"))
            }
        }

        val jsTest by getting {

        }
    }
}

android {
    compileSdkVersion(App.compileSdk)

    sourceSets {
        getByName("main") {
            manifest.srcFile("src/androidMain/AndroidManifest.xml")
            java.srcDirs("src/androidMain/kotlin")
            res.srcDirs("src/androidMain/res")
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude("META-INF/*")
    }

}

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutinesCore}")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.serializationCommon}")
    implementation("io.ktor:ktor-client-android:${Versions.ktor}")
    implementation("io.ktor:ktor-client-json-jvm:${Versions.ktor}")
    implementation("io.ktor:ktor-client-serialization-jvm:${Versions.ktor}")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
    kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
    kotlinOptions.jvmTarget = "1.8"
}
c
This simply can't work, need a ktot build with 0.20
s
I'm a little lost as to what you mean?
kotlinx-serialization-runtime
is already at 0.20.0? with
client-serialization-jvm
at 1.3.1.
r
client-serialization-jvm:1.3.1
is only compatible with
kotlinx-serialization-runtime:0.14.0
. Which requires Kotlin 1.3.61 and not 1.3.70. Need to wait for ktor to update.
👍 1
s
Ok, thank you for this. 🙂 I having been pulling hair all day