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

Jose Garcia

10/18/2023, 11:50 AM
Hey guys, I’m creating an XCFramework using kotlin multiplatform. Is it possible to add any settings on this block of code of my build.gradle to enable Swift’s module stability?
Copy code
kotlin {
  val xcf = XCFramework()
  val iosTargets = listOf(iosX64(), iosArm64(), iosSimulatorArm64())

  iosTargets.forEach {
      it.binaries.framework {
          baseName = "OriginalFramework"
          isStatic = true
          embedBitcode(BitcodeEmbeddingMode.BITCODE)
          linkerOpts(
            "-lsqlite3",
             )
          xcf.add(this)
      }
  }
AFAIK to do this I think I need XCode build setting “BUILD_LIBRARY_FOR_DISTRIBUTION” set to YES but I don’t have access to this setting as this is done using the multiplatform plugin. I think this is linked to a Swift feature called “Library Evolution Support”
a

a-dd

10/18/2023, 11:53 AM
Hey 👏 What are you trying to achieve with this setting? Module stability is about binaries built by Swift compiler (and compatibiltiy with the other versions of compiler) and Kotlin doesn’t use it.
j

Jose Garcia

10/18/2023, 12:04 PM
Hi Artem, so the idea is to use an XCFramework (I call this
OriginalFramework
) I can distribute to my customers. However, when we started to test out the use of this framework we realised that our API wasn’t too elegant. For example if we had a class named
MyClass
on a
MyClass.kt
file inside our kotlin code, when it was compiled and distributed to this framework we would have to use it as
MyClassKt()
and we considered this is was not a very elegant API for out iOS customers so we decided to create a wrapper xcframework (
WrapperFramework
) that would contain a Swift class
MyInterface.swift
that would call the methods from our original framework. On
MyInterface.swift
I’m getting a compile error when I try to `import OriginalFramework`:
Copy code
Module 'OriginalFramework' was not compiled with library evolution support; using it means binary compatibility for 'WrapperFramework' can't be guaranteed
The
OriginalFramework
was created via Kotlin multiplatform plugin The
WrapperFramework
was created via create new Framework from Xcode
4 Views