Is it possible to distribute Kotlin Multiplatform ...
# multiplatform
m
Is it possible to distribute Kotlin Multiplatform packages which bundle Swift code with
expect/actual
? Rather than using Obj-C interoperability? For instance I wish to build a Downloader package where the iOS platform specific is written in Swift. This could also go as far as building a package which depends on another remote Swift Package.
👀 1
or would such a thing require more setup on the consumer/client side? injecting the Swift implementation into a Kotlin package?
or using libraries such as swift-klib-plugin? though this seems more geared again toward using interoperability
b
swift-klib-plugin works and gets you there, but uses out-of-date tooling. you can use our fork in the meantime until it is updated upstream. just add it as a submodule into your project and plug it into your
settings.gradle.kts
like so:
Copy code
pluginManagement {
    includeBuild("swift-klib-plugin")
}
👍 1
m
so this is best option for combining Swift code in a KMP package? Just means the entry points need to be ObjC compatible? in order for introp to work
suppose it will need an interstitial definition for the actual expectation?
p
I believe the current status is just these 2 alternatives. In regards to the above plugin, I couldn't find any example of adding 3rd party swift packages as dependency in the Gradle DSL. Do I have to do that manually in the generated
Package.swift
file?
j
SKIE also has something interesting since 0.8: https://skie.touchlab.co/changelog/0.8.0
👀 1
p
Documentation doesn't show much but seems promising
m
b
you are right, third-party packages are not supported by the swift-klib-plugin
m
there is also this, not sure if there is something similar for recently in development. https://github.com/PaGr0m/kotlin-spm-plugin
p
It seems that the kotlin-spm-plugin falls under the same category:
Copy code
NOTE: At the moment, Kotlin is not directly compatible with Swift. Therefore, you can only connect Objective-C libraries that have a Swift package file.
Although the gradle tasks are handy.
For the typical indie developer wrapping a big swift library with @obj-c may not scale. For a person that is paid for just doing this is a different story but the problem is what company will do it and if they will be willing to share after. I keep seeing the solution that distributes a KMP library accompanied with an SPM package, that provides the interface wrappers, as the most scalable.
m
@Pablichjenkov last comment requires something like klib plugin? or are you suggesting otherwise
p
You really don't need an external plugin, existing gradle tasks and SPM capabilities can make it possible to distribute code in a similar way(not embedding
.swift
files in the umbrella but rather providing them in a separate swift package). I also was looking for embedding swift files in the generated KMP .xcframework as a solution for distribution. But I ended up realizing what these plugins do, you can achieve it manually in Package.swift. The solution I use, relies on manually creating an abstraction bridge(lot of interfaces in kmp side) in the umbrella framework. Then the implementations of these interfaces will live in a swift package on some repo in GitHub. The consumer project will integrate the umbrella.framework(either locally or remote hosted) and will also include the swift package with the actual implementations. At compile time Xcode will resolve all the dependencies.
m
@Bernd Prünster thought I'd let you know that swift-klib-plugin fork worked for me; thanks heaps!
b
Happy to hear that! I was contemplating submitting a PR, but the maintainer seems to be too swamped to spend any time on it at the moment.
m
Might also share another repo I put together to illustrate how one repo could serve both KMP Package and a Swift Package: https://github.com/markst/radioplayer-kt
thank you color 1