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

Adi Pilav

09/26/2023, 4:28 PM
Hi there! I have issues with my KMM module. I wrote an
expect
class in
commonMain
and
actual
implementations in
androidMain
,
jvmMain
and
iosMain
. However, Android Studio requires me to add additional
actual
implementation in
main
source set, which shouldn't even exist, per my understanding at least. When I tried to use this module as a project dependency in another feature module, the feature module was actually using the implementation from the
main
source set instead of
androidMain
. I am using Kotlin 1.7.10 and Android Studio Electric Eel | 2022.1.1 Patch 2. Am I doing something wrong here? I'll post
build.gradle
configuration in the reply.
Copy code
plugins {
    id 'org.jetbrains.kotlin.multiplatform'
    id 'org.jetbrains.kotlin.plugin.serialization'
    id 'com.android.library'
}

apply from: "../dependencies.gradle"

kotlin {
    jvm()
    android()
    ios()
    iosSimulatorArm64()

    sourceSets {
        commonMain.dependencies {
            ...
        }

        androidMain {
            dependsOn(commonMain)
        }

        iosMain {
            dependsOn(commonMain)
        }

        iosSimulatorArm64Main {
            dependsOn(iosMain)
        }

        jvmMain {
            dependsOn(commonMain)
        }

        jvmTest.dependencies {
            ...
        }
    }
}

android {
    compileSdk 33
    sourceSets.named("main") {
        manifest.srcFile("src/androidMain/AndroidManifest.xml")
    }
    defaultConfig {
        minSdk 24
        targetSdk 33
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
}
j

Jeff Lockhart

09/26/2023, 4:42 PM
Is there a reason you're not using a newer version of Kotlin? There have been a lot of fixes and improvements in KMP since 1.7.10.
👍 1
a

Adi Pilav

09/26/2023, 4:59 PM
Yeah, you are right. I will try to update the Kotlin and see if that helps, I just hope it doesn't require a newer Java version as I have to use Java 11. Thank you @Jeff Lockhart for the feedback, I appreciate your input!
j

Jeff Lockhart

09/26/2023, 5:05 PM
You won't need to update Java. Kotlin supports a minimum of Java 8 since 1.5.
👍 1
5 Views