ioskotlinintellij-ideajetbrains-idemultiplatform

IntelliJ and Kotlin Multiplatform - "Kotlin Not Configured" warning for iOS source


I am working on a Kotlin Multiplatform project that encompasses both an Android and iOS implementation. I am using the Gradle Kotlin DSL to build the project. After upgrading to Kotlin 1.8 from 1.6, IntelliJ now displays a yellow warning reading Kotlin not configured above any Kotlin file in the iOS portion of the library. I am also no longer able to use code completion in the affected files.

My build.gradle.kts reads as follows:

import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

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

kotlin {
    android()

    val xcf = XCFramework()
    listOf(iosSimulatorArm64(), iosX64(), iosArm64("ios")).forEach {
        it.binaries.framework {
            baseName = "SharedLibrary"
            xcf.add(this)
        }
    }

    sourceSets {
        val commonMain by getting

        val androidMain by getting

        val iosMain by getting
        val iosSimulatorArm64Main by getting
        iosSimulatorArm64Main.dependsOn(iosMain)
        val iosX64Main by getting
        iosX64Main.dependsOn(iosMain)
    }
}

android {
    namespace = "com.example"
    compileSdk = 32
    defaultConfig {
        minSdk = 27
        targetSdk = 32
    }
}

How can I resolve this warning?


Solution

  • The issue is that IntelliJ doesn't read that the Kotlin standard library should be included in the iOS part of the library. Explicitly declare org.jetbrains.kotlin:kotlin-stdlib as a dependency of the common module, like so:

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib")
            }
        }
    }
    

    After allowing IntelliJ to sync with Gradle, the issue should be resolved!