Kotlin / kotlin-examples

Various examples for Kotlin
3.21k stars 1.04k forks source link

mpp-iOS-Android: Unresolved reference: android #97

Open tttzof351 opened 5 years ago

tttzof351 commented 5 years ago

When I just write as actual fun platformName(): String { return "Android " + android.os.Build.VERSION.BASE_OS } in SharedCode/src/androidMain/kotlin/actual.kt I get: Unresolved reference: android so it's mean that android platform module don't support android sdk :(

paderick commented 5 years ago

Same problem here. Android packages are not available in the android specific part. But in the ios specific part I can use e.g. the Foundation import.

Maragues commented 4 years ago

Could you please update this example? You are making a big investment into KMP, but the introductory example is almost 1 year old and it doesn't show how to reference android code.

For those who end up here looking for a solution, this tutorial helped me

Here are the relevant parts of my build.gradle.kts

plugins {
    id("com.android.library")
    kotlin("multiplatform")
}

android {
    compileSdkVersion(Versions.Android.compileSdk)

    defaultConfig {
        minSdkVersion(Versions.Android.minSdk)
        targetSdkVersion(Versions.Android.targetSdk)
    }

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

group = "com.kolibree"
version = "1.0-SNAPSHOT"

kotlin {
    android() 

   [...]