I seem to be having an issue with my multi platfor...
# multiplatform
s
I seem to be having an issue with my multi platform config, Its not autocompleting for ios or js. When I try to implement a
map
across all three platforms, the packages aren’t being imported. Has anyone else had this issue and managed to rectify it?
I’ve tried in both Android Studio and Intellij Cleaned all the caches and files. Reimported and still having the same issue. I am running on 1.3.70 EAP so the issue might lye here… but im not sure
r
There's a lot of subtle configuration things that can cause this. Posting your Gradle files or linking your project might help
s
Copy code
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.multiplatform")
    id("org.jetbrains.kotlin.native.cocoapods")
    id("kotlin-dce-js")
}

version = Versions.cocoapodVersion

kotlin {

    cocoapods {
        summary = "Shared Code for Android and iOS"
        homepage = "Link to a Kotlin/Native module homepage"
    }

    android()

    js() {
        targets {
            browser {
                @Suppress("EXPERIMENTAL_API_USAGE")
                dceTask { keep("kotlin.defineModule") }
            }
        }
    }

    val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iOSTarget("ios") {
        compilations {
            val main by getting {
                kotlinOptions.freeCompilerArgs = listOf("-Xobjc-generics")
            }
        }
    }

    sourceSets["commonMain"].dependencies {
        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}")
        implementation("org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70-eap-274")
    }

    sourceSets["iosMain"].dependencies {
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:${Versions.coroutinesCore}")
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:${Versions.serializationCommon}")
        implementation("io.ktor:ktor-client-ios:${Versions.ktor}")
        implementation("io.ktor:ktor-client-json-native:${Versions.ktor}")
        implementation("io.ktor:ktor-client-serialization-native:${Versions.ktor}")
        implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.70-eap-274")
    }

    sourceSets["jsMain"].dependencies {
        implementation(kotlin("stdlib-js", version = "1.3.70-eap-274"))
    }
}

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
    }
}

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("androidx.lifecycle:lifecycle-extensions:${Versions.lifecycleVersion}")
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycleVersion}")

    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}

tasks {
    register("buildNpm") {
        doLast {
            copy {
                from(zipTree("$buildDir/libs/common-js-$version.jar"))
                eachFile {
                    filter { line ->
                        line.replace("require('kotlin')", "require('./kotlin.js')")
                    }
                }
                into("$buildDir/npm")
            }
            copy {
                from("${rootProject.buildDir}/js/packages/common/kotlin-dce/kotlin.js")
                into("$buildDir/npm")
            }
        }
    }
    named("buildNpm") {
        dependsOn("jsJar", "processDceJsKotlinJs")
    }
    named("build") {
        dependsOn("buildNpm")
    }
}
Hey Russ, this is my current gradle set up. It was working in the past but seems to have just stopped. I’ve tried resetting everything and still have the same issue. Ill link my parent gradle file also.
Copy code
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()
        maven(url = "<https://dl.bintray.com/kotlin/kotlin-eap>")

    }

    dependencies {
        classpath("com.android.tools.build:gradle:${Versions.gradle}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
        //classpath("org.jetbrains.kotlin:kotlin-frontend-plugin:${Web.frontEndPlugin}")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle.kts files
    }
}

allprojects {

    repositories {
        google()
        jcenter()
        mavenCentral()
        maven(url = "<https://dl.bintray.com/kotlin/kotlin-eap>")
    }
}
r
Not totally sure off-hand. One thing that jumps out is the js-dce stuff has been rolled into the main multiplatform and js plugins, so you probably don't need to apply it manually. I think some of the usage also changes but I'm less close to the js side of things. Not sure if that's causing your issues though. Could also be eap stuff or some other form of ide/hradle mismatch.
s
The DCE stuff at the bottom is a task that can bundle a NPM module and use the Kotlin DCE’d code, but the original KT -> JS code from the zipped jar. Otherwise the module is over 2mb, with this little script it sits at 53kb. I think im with you on that. Ill revert to 1.3.61 for now and see if it makes a difference. Ill let you know. 🙂 Thank you
Ok, reverting to 1.3.61 and cleaning all the build folders and removing all the *.iml files OUTSIDE of Android Studio, then reimporting has seems to have sorted the issue.