This gist demonstrates how to build a Kotlin MPP library so that the iOS sourceSet
depends on and uses an iOS Framework as a dependency.
Key ideas:
- We use Carthage to retrieve/build the iOS Framework.
- We use cinterop to create bindings allowing us to use the iOS Framework from Kotlin
- We build and publish the library using
./gradlew publishToMavenLocal
- We build and publish klib artifacts for both the
arm64
andx86_64
architectures, you can easily addarm32
if you need. - Note that the publish process also publishes a
cinterop
klib
artifact, allowing dependents to also know about the iOS Framework headers.
You can find a gist explaining how to use such library in an iOS app here.
More notes:
- The
.def
file's name contains its path with/
replaced with-
. - I have no idea what I'm doing in this
.def
file, but it works. Half the entries are probably useless.
Thanks for the helpful infos!
It looks like with Kotlin 1.3.50 linkerOpts doesn't exist anymore on the
KotlinNativeCompilation
target. It exsist in theDefaultCInteropSettings
, but that prints out a warning that it's not used anymore.Is
target.binaries.forEach { it.linkerOpts ... }
the correct way to handle this? I've tried it but so far I failed atReason: image not found
Edit: for unit tests and their dynamic frameworks: copy the frameworks to the location of the kexe in a directory called
Frameworks
and voilà, it works.