Reputation: 31
I try to use Kotlin multiplatform to create a library for iOS and Android. I follow this guide https://kotlinlang.org/docs/mobile/add-dependencies.html#add-a-library-without-cocoapods to connect our Objective-C library Encryption
with this gradle config in my project:
kotlin {
android()
val ios = listOf(iosX64(), iosArm64())
configure(ios) {
compilations.getByName("main") {
val Encryption by cinterops.creating {
defFile("src/iosX64Main/cinterop/Encryption.def")
includeDirs("src/iosX64Main/libs/Encryption")
}
}
binaries.all {
linkerOpts("-L/proj_abs_path/src/iosX64Main/libs", "-lEncryption.a")
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
implementation("io.ktor:ktor-client-core:$ktor_version")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.2.1")
implementation("io.ktor:ktor-client-okhttp:$ktor_version")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13")
}
}
val iosX64Main by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktor_version")
}
}
val iosArm64Main by getting {
dependsOn(iosX64Main)
}
val iosX64Test by getting
}
}
And when I run commonTest for iosX64, I get
> Task :linkDebugTestIosX64
e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
ld: library not found for -lEncryption.a
> Task :linkDebugTestIosX64 FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':linkDebugTestIosX64'.
What I'm doing wrong and how can I include my library as static lib (connect at compile time)?
Upvotes: 3
Views: 2053
Reputation: 4689
Make sure Xcode's CoreSimulator is running already when you test for iOS. Kotlin multiplatform does not seem to be able to start the iOS simulator, but it can run tests on the simulator if it is running already.
Upvotes: 2