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

Gleb

02/08/2023, 1:55 AM
Hi all. We want to try using KMP to modify an existing Kotlin library to be consumed by multiple targets. It will be mainly used by some client applications (such as Android and JS: React Native, browser) 1. Is there any obvious problems that may arise? The code in current codebase is (somewhat) platform agnostic: only one library is JVM 2. First thing that I noticed is JSExport not allowed on suspend functions, does it mean our public API must be split between JVM and JS? (I.e. I have
suspend foo(): String
in
MyClass
. I would like to expose it to the developer using my library. I will need to create
expect MyClassAPI
that has different iml for JS and JVM:
fooAPI(): Promise<String>
and
suspend fooAPI(): String
. Both calling foo internally. We are still and research phase. Alternative would be to re-implement kotlin library in typescript, but I would like to hear from people with experience opinion on the topic. Thanks!
e

Evegenii Khokhlov

02/08/2023, 6:03 AM
about second question: I believe that API shouldn’t be split, it is perfectly fine that your multiplatform library API has suspend functions. I suggest creating additional wrappers with
JSExport
in js source set for yours JS target and don’t use
actual / expect
for this task
g

Gleb

02/08/2023, 6:02 PM
The problem is that I have an
expect
class with suspend function which I want to export. Currently, I can't really do that because of JSExport restrictions.
9 Views