androidkotlin-multiplatform

(KotlinSourceSet with name 'iosMain' not found.) How can I add android as a build target to a Kotlin Multiplatform project


There is such a topic on the website stackoverflow.com: KotlinSourceSet with name 'androidMain' not found..

I have a similar problem: "KotlinSourceSet with name 'iosMain' not found."

I don't quite understand how to resolve it. Help me please. [![Task 1][1]][1] [![Task 2][2]][2]

Update: resolved, now I got: Built iOS application: failed with code 65 ... What should I do to fix it?


Solution

  • The generic ios sourceset has been deprecated and you now have to specify the targets more explicitly. This means that for the adding of targets instead of adding a generic ios(), you specify the separate targets:

    kotlin {
        androidTarget {
            compilations.all {
                kotlinOptions {
                    jvmTarget = "1.8"
                }
            }
        }
    
        listOf(
            iosX64(),
            iosArm64(),
            iosSimulatorArm64()
        ).forEach {
            it.binaries.framework {
                baseName = "shared"
            }
        }
    
        // ios() // -> This has been deprecated
        iosArm64()
        iosX64()
        iosSimulatorArm64()
    

    And when specifying the sourcesets, you add their main/test targets:

    sourceSets {
    ...
    val iosArm64Main by getting {
        dependencies {
          ...
        }
    }
    val iosArm64Test by getting {
        dependencies {
          ...
        }
    }
    val iosX64Main by getting {
        dependencies {
          ...
        }
    }
    val iosSimulatorArm64Main by getting {
        dependencies {
          ...
        }
    }