https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kroppeb

07/10/2020, 8:48 AM
I'm getting these kind of errors:
Cannot access built-in declaration '...'. Ensure that you have a dependency on the Kotlin standard library
I'm confused as to why it can't find the stdlib?
👍 1
r

russhwolf

07/10/2020, 12:21 PM
You need to also have
implementation(kotlin("stdlib"))
in your
jvmMain
dependencies.
k

Kroppeb

07/10/2020, 12:40 PM
thank you
r

russhwolf

07/10/2020, 12:41 PM
eep had a copy-paste error. Should be
kotlin("stdlib")
v

vashisthg

07/11/2020, 12:43 PM
I am also getting same error when I try to run
jvmTest
Copy code
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
}

kotlin {
    //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 = "recommendations"
            }
        }
    }

    jvm("android")
    jvm()

    sourceSets["commonMain"].dependencies {
        implementation(kotlin("stdlib-common"))
    }

    sourceSets["androidMain"].dependencies {
        implementation(kotlin("stdlib"))
    }

    sourceSets["jvmMain"].dependencies {
        implementation(kotlin("stdlib-common"))
    }

    sourceSets["commonTest"].dependencies {
        implementation(kotlin("test-common"))
        implementation(kotlin("test-annotations-common"))
    }

    sourceSets["androidTest"].dependencies {
        implementation(kotlin("test"))
        implementation(kotlin("test-junit"))
    }

    // JVM-specific tests and their dependencies:
    jvm().compilations["test"].defaultSourceSet {
        dependencies {
            implementation(kotlin("test"))
            implementation(kotlin("test-junit"))
        }
    }
}

val packForXcode by tasks.creating(Sync::class) {
    val targetDir = File(buildDir, "xcode-frameworks")

    /// selecting the right configuration for the iOS
    /// framework depending on the environment
    /// variables set by Xcode build
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val framework = kotlin.targets
        .getByName<KotlinNativeTarget>("ios")
        .binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)

    from({ framework.outputDirectory })
    into(targetDir)

    /// generate a helpful ./gradlew wrapper with embedded Java path
    doLast {
        val gradlew = File(targetDir, "gradlew")
        gradlew.writeText("#!/bin/bash\n"
            + "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
            + "cd '${rootProject.rootDir}'\n"
            + "./gradlew \$@\n")
        gradlew.setExecutable(true)
    }
}

tasks.getByName("build").dependsOn(packForXcode)
Fixed by adding
Copy code
sourceSets["jvmMain"].dependencies {
        implementation(kotlin("stdlib-jdk8"))
    }
37 Views