Hi! I have started a new multiplatform project in ...
# serialization
d
Hi! I have started a new multiplatform project in IDEA (kotlin version 1.3.61), added the classpath, added
id("kotlinx-serialization") version "1.3.61"
to the plugins block and
implementation(serialization("-common"))
dependency to commonMain. Then I try to annotate a data class with
@Serializable
and IDEA says it fine, but when running gradle build it says
Cannot access 'Serializable': it is internal in '<http://kotlin.io|kotlin.io>'
. It seems similar to this issue: https://github.com/Kotlin/kotlinx.serialization/issues/395 but here the solution was to add the plugin to the plugin block - which I have already done. Any suggestion what might cause this?
t
d
Thanks for your reply. Here is my current `build.gradle.kts`:
Copy code
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

group = "com.huma"
version = "0.0.1"

plugins {
    kotlin("multiplatform")
    id("kotlinx-serialization") 
}


repositories {
    mavenCentral()
    jcenter()
    maven(url = "<https://kotlin.bintray.com/kotlinx>")
    maven(url = "<https://repo1.maven.org/maven2>")
    maven(url = "<https://dl.bintray.com/kotlin/kotlin-eap>")
}

kotlin {
    jvm("android") {
        tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }


    //select iOS target platform depending on the Xcode environment variables
    val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iOSTarget("ios") {
        binaries {
            framework {
                baseName = "Common"
            }
        }
    }

    sourceSets {
        val ktorVersion = "1.2.6"
        val coroutinesVersion = "1.3.2-1.3.60"
        val serializationVersion = "0.14.0"

        fun kotlinx(module: String, version: String) =
            "org.jetbrains.kotlinx:kotlinx-$module:$version"

        fun coroutines(module: String = "") =
            kotlinx("coroutines-core$module", coroutinesVersion)

        fun serialization(module: String = "") =
            kotlinx("serialization-runtime$module", serializationVersion)

        fun ktorClient(module: String, version: String = ktorVersion) =
            "io.ktor:ktor-client-$module:$version"

        all {
            languageSettings.useExperimentalAnnotation("kotlin.Experimental")
        }
        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation(coroutines("-common"))
                implementation(serialization("-common"))
                implementation(ktorClient("core"))
                implementation(ktorClient("json"))
                implementation(ktorClient("serialization"))
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(kotlin("stdlib"))
                implementation(coroutines())
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test"))
                implementation(kotlin("test-junit"))
            }
        }
        val iosMain by getting {
            dependencies {
                implementation(coroutines("-native"))
            }
        }
        val iosTest by getting {

        }
    }
}
// Some gradle tasks here...
Any obvious mistakes here?
t
You don't declare
serialization-runtime
in every target (like in my example)
In example
serialization
declared for
common
.
js
&
jvm
. In your example - only for
common
d
But do you need the serialization dependency for every target when you only need it in common?
I might as well try. Pretty desperate 🙂
Still the same error:
Unresolved reference: serialization
on import. But I can still cmd+click the import and inspect the source… 🙄
t
Still the same error
In common tests?
d
Same error inn commonMain when trying to import `kotlinx.serialization`:
Copy code
package main.models

import kotlinx.serialization.*

@Serializable
data class AuthProvider(
    val name: String,
    val authUrl: String
)
IDEA says it is fine, I can even cmd+click serialization and view the source, but gradle gives me this error:
Unresolved reference: serialization
Have you ever encountered the IDE and gradle saying different things?
t
In
2019.3
some times
Do you run tests in
commonTest
?
d
Ok, I also use 2019.3. Well, as this is a new project there are no tests yet, but yes, they will be in commonTest eventually.
t
commonTest
- the main suspect
Tests couldn't run without runtime