Hi folks, I am trying to build a KMP library for A...
# multiplatform
m
Hi folks, I am trying to build a KMP library for Android and iOS. I followed this tutorial https://kotlinlang.org/docs/mpp-create-lib.html But when I try to use the library in iOS project I get this error
Copy code
the linked and embedded framework is missing one or more architectures required by this target: arm64
I am using M1 Mac and trying to run it with simulator so that will be an issue (since we see no issue on other architectures). The weird part is that the template task mentions arm64 architecture:
Copy code
val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework =
        kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
When I try KMM project I don't have this problem (but then the library is linked, so it is a different scenario). Any ideas or experience with this?
1
a
Hello! I was unable to find any recent mentions of this error, but I would like to point out the fact that using
packForXcode
task might be an obsolete practice: https://blog.jetbrains.com/kotlin/2021/07/multiplatform-gradle-plugin-improved-for-connecting-kmm-modules/ Even from the code you share, it determines Device and Simulator by the SDK name prefix, which is not taking iosSimulatorArm64 into the count - that one target has
iphonesimulator
SDK name prefix and
Arm64
target name suffix. If you also want to get more info about how the
embedAndSignAppleFrameworkForXcode
task defines targets to work with M1 simulators correctly, consider looking at https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plug[…]kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/AppleSdk.kt
🙏 2
👌 2
m
@Artyom Degtyarev [JB] thank you, I had a hunch that might be true :) However this is still part of the template that is generated when I create KMP library project in IJ. Should I create a ticket for this?
a
I think this one describes the problem correctly: https://youtrack.jetbrains.com/issue/KTIJ-19222. You can upvote it and share some details of your use-case in the comment section, for example, why are you using IJ instead of AS. These steps would help the developers team to calculate this ticket’s priority more accurately.
m
To be honest I was not sure whether it is recommended to use KMM also for library development.