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

Vladimir Vainer

10/10/2023, 8:04 AM
Can I have the following: 1. Create a KMP Library MyAwesomeSDK, which provides an interface to encode / decode / verify JWT (Needed for operation of my AwesomeSDK) 2. Create an iOS XCFramework library MyAwesomeIOSDeps, that implements this interface with the help of SwiftJWT. 3. Send my consumers the maven published KMP Library MyAwesomeSDK and MyAwesomeIOSDeps.xcframework 4. My Consumer will create an iOS Project / KMP App, add dependency on MyAwesomeSDK and MyAwesomeIOSDeps 5. My Consumer will init MyAwesomeSDK from swift or kotlin with:
import MyAwesomeSDK
import MyAwesomeIOSDeps
MyAwesomeSDK.Init(MyAwesomeIOSDeps.JWTImpl())
r

Rick Clephas

10/10/2023, 10:00 AM
No at the moment this won’t work. The reason being that every KMP framework is considered to have different types. So
MyAwesomeSDK.A
wouldn’t be the same type as
shared.A
(where
shared
is the consumers shared Kotlin module with a dependency on
MyAwesomeSDK
). Also see https://youtrack.jetbrains.com/issue/KT-42250/Support-compiling-Kotlin-module-to-Swift-Obj-C-module-that-doesnt-contain-all-dependencies
However making your KMP MyAwesomeSDK depend on your own ObjC library does work. This effectively decouples your iOS framework from the Kotlin library by using an intermediate ObjC library.
v

Vladimir Vainer

10/10/2023, 10:06 AM
But then i cannot package it with my kmp library. And have to ask consumers of my library to manually link with my objc lib
r

Rick Clephas

10/10/2023, 10:08 AM
Correct, unless the ObjC framework only contains header declarations. In which case linking the iOS (and ObjC) framework in the iOS client is enough.