Skip to content

Getting Started

Requirement

  • macOS With Xcode 16 and later
  • Kotlin : 2.1.21 and later
    • It's always recommended to use the latest version of Kotlin.
  • Gradle : 8.12 and later

Plugins

Gradle Plugin Portal Version

build.gradle.kts
plugins {
    id("org.jetbrains.kotlin.multiplatform")
    id("io.github.frankois944.spmForKmp") version "[version]"
}

Gradle Properties

gradle.properties
kotlin.mpp.enableCInteropCommonization=true

Initial Configuration

build.gradle.kts
// List of targets
kotlin {
    listOf(
        iosArm64(),
        iosSimulatorArm64()
        // and more Apple targets...
    ).forEach { target ->
        // `cinteropName` is recommended when using a list of native target
        // Or when you want to keep the compatibility with the legacy way (cf: [cinteropName])
        // If not set, It will take the name of the current Target
        target.swiftPackageConfig(cinteropName = "[cinteropName]") {
            // create a new directory at `src/swift/[cinteropName]`
        }
    }
}

// For a single target

kotlin {
    iosArm64 {
        swiftPackageConfig {
            // create a new directory at `src/swift/iosArm64`
        }
    }
}
Legacy (< 1.1.0)
build.gradle.kts
kotlin {
    listOf(
        iosArm64(),
        iosSimulatorArm64()
        // and more Apple targets...
    ).forEach {
        it.compilations {
            val main by getting {
                // Choose the cinterop name
                cinterops.create("[cinteropName]")
            }
        }
    }
}
build.gradle.kts
swiftPackageConfig {
    create("[cinteropName]") { // must match with cinterops.create name
    }
}

swiftPackageConfig reference