I get this error message when I annotate a class w...
# serialization
p
I get this error message when I annotate a class with Serializable
Copy code
Cannot access 'Serializable': it is internal in '<http://kotlin.io|kotlin.io>'
n
wrong import ?
p
Copy code
plugins {
    kotlin("multiplatform") version "1.3.72"
    kotlin("plugin.serialization") version "1.3.72"
}

repositories {
    mavenCentral()
    jcenter()
}

kotlin {

    val korioVersion = "1.10.0"
    val serializationVersion = "0.20.0"

    // For ARM, should be changed to iosArm32 or iosArm64
    // For Linux, should be changed to e.g. linuxX64
    // For MacOS, should be changed to e.g. macosX64
    // For Windows, should be changed to e.g. mingwX64
    mingwX64("mingw") {
        binaries {
            executable {
                entryPoint("barcodeParser.main")
            }
        }
    }

    jvm {

    }

    js {
        browser {

        }
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation(kotlin("stdlib-common"))
                api("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationVersion")
            }
        }
        commonTest {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        jvm().compilations["main"].defaultSourceSet {
            dependencies {
                implementation(kotlin("stdlib-jdk8"))
            }
        }
        jvm().compilations["test"].defaultSourceSet {
            dependencies {
                implementation(kotlin("test-junit"))
            }
        }
        mingwX64().compilations["main"].defaultSourceSet {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serializationVersion")
            }
        }
        mingwX64().compilations["test"].defaultSourceSet {

        }
        js().compilations["main"].defaultSourceSet {
            dependencies {
                implementation(kotlin("stdlib-js"))
            }
        }
        js().compilations["test"].defaultSourceSet {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
    }
}
What did I do wrong?
n
should be in package
kotlinx.serialization
p
I think I followed exactly the tutorial
n
maybe idea did the wrong import in the .kt file ?
so you have this import?
import kotlinx.serialization.*
p
Copy code
import kotlinx.serialization.*
Now I don't have the error in the idea but still when I try to compile it for jvm or native
n
because
Serialization
should not be in
<http://kotlin.io|kotlin.io>
p
Hmm but why would this cause an error if I import the correct class?
n
i gues you have gradle metadata enabled ? otherwise the dependencies won't be in your different targets
p
Unresolved reference: serialization
n
check your dependencies
p
You mean this line in settings.gradle:
Copy code
enableFeaturePreview('GRADLE_METADATA')
n
i am guessing it does need to find the jvm and native things for serialization-runtime
a buildscan or just output of dependenciesInsight
p
message has been deleted
Output of dependencies
I can use Serializable in common code, right?
r
You're missing
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-jvm:$serializationVersion")
in your jvm dependencies and
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serializationVersion")
in js. Or you can change the common dependency to
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serializationVersion")
and then you don't need the rest
p
Thanks, the second suggestion seems to work
Why does this work though? Seems very counterintuitive to add the native dependency to the common dependencies
r
Historical reasons, I guess. The -native dependency is the one that includes metadata to get other platforms automatically, so you don't need to add each native platform manually. But that also works for jvm and js, so you can just use -native from common.
p
I see, maybe this should be changed then. Or at least it should be explained in the documentation at least.
💯 1