I can currently build the iOS app that relies upon...
# multiplatform
t
I can currently build the iOS app that relies upon my KMM module but the Kotlin files in
iosMain
, when viewed in Android Studio, have broken syntax highlighting and I get a warning that Kotlin is not configured. If I configure it for the module, I get some extra blocks added to my KMM module's Gradle file (as well as my Android app's Gradle file) which doesn't fix the syntax highlighting in the
iosMain
Kotlin files. It also breaks my Android app config and seems to make some other broken configuration (like adding
classpath(kotlinModule("gradle-plugin", kotlin_version))
where
kotlinModule
can't be resolved) and adding
androidx-core:core-ktx:+
and
stdlib-jdk7
to my KMM module's dependencies (not just for
androidMain
) What's the proper way to configure Kotlin for
iosMain
and fix the syntax highlighting?
this may be related to another problem I'm suddenly seeing: my
commonMain
has an
expect class
which I implement as an
actual class
in
androidMain
and
iosMain
. But there's a warning on the
expect class
that says: "Class 'ClassName' has several compatible actual declarations in modules SharedModule, SharedModule"
I'm pretty sure there's something wrong about this portion of my
SharedModule
Gradle file but I don't know exactly:
Copy code
kotlin {
    android()

    val iosArm64 = iosArm64()
    val iosX64 = iosX64()
    val iosSimulatorArm64 = iosSimulatorArm64()

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

                val kotlin_serialization_json_version = "1.3.1"
                val doinst_x_normalize_version = "1.0.4"
                val korlibs_krypto_version = "2.0.0.999"

                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_serialization_json_version")
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.0")
                implementation("com.benasher44:uuid:$BENASHER44_UUID_VERSION")
                implementation("com.doist.x:normalize:$doinst_x_normalize_version")
                implementation("com.soywiz.korlibs.krypto:krypto:$korlibs_krypto_version")
                implementation("com.squareup.sqldelight:runtime:$SQL_DELIGHT_VERSION")
            }
        }

        val androidMain by getting {
            dependsOn(commonMain)

            dependencies {
                implementation("com.squareup.sqldelight:android-driver:$SQL_DELIGHT_VERSION")
            }
        }

        val iosMain by creating
        val iosTest by creating
        listOf(iosArm64, iosX64, iosSimulatorArm64).forEach {
            it.binaries {
                framework {
                    baseName = "SharedCode"
                }
            }

            fun KotlinDependencyHandler.sharedImplementations() {
                implementation("com.squareup.sqldelight:native-driver:$SQL_DELIGHT_VERSION")
            }

            getByName("${it.targetName}Main") {
                dependsOn(iosMain)
                dependencies {
                    sharedImplementations()
                }
            }
            getByName("${it.targetName}Test") {
                dependsOn(iosTest)
                dependencies {
                    sharedImplementations()
                }
            }
        }
    }
}
it also looks like the
actual class
in
iosMain
is described as belonging to
MyProject.SharedCode.iosMain
though the
actual class
in
androidMain
is in
MyProject.SharedCode
and the
expect class
is also in
MyProject.SharedCode
.
It seems the fix was to declare only one iOS target (with the name
ios
) based on environment variables to avoid creating multiple iOS targets
l
In my case I had to turn ON
Android plugin
in Intellij, that allowed me to correctly index imports and classes usages