guys, I'm trying to make a KMP app which works on ...
# multiplatform
n
guys, I'm trying to make a KMP app which works on mac, win and linux. However, I need to call the OS specific APIs. Also, I want to use compose for the UI. Is this possible? asking because I'm having issue with configuring the build.gradle.kts sourceSets
k
yes it's possible, you can use CMP to create the common UI, and for the specific logic that needs to be implemented with each platform native API you can use the mechanism of expect/actual, checkout the documentation here: https://kotlinlang.org/docs/multiplatform-expect-actual.html#expected-and-actual-functions
n
thanks @Kaouther , I will check it out
Hmm, doesn't seem to be correct. I need to write OS specific APIs at lower level and the upper level is compose UI which will invoke the lower level
both should be incorporated in a DMG for macos (for example)
k
ok, sorry i may missed this point, if the OS API is not accessible in Kotlin/native then in that case you need to write your code using the OS specific API in the target directory (for example in iOS under iosApp) then warp it and call it in the actual part. i did this once for iOS it worked, but not sure for other targets
n
android and iOS will works, because compose available on both, I think. But for desktop, compose only available on Kotlin/JVM, not on Kotlin/Native. So if I write OS specific APIs then I can't use compose
k
well actually compose mutliplatorf is available for Kotlin/native, iOS is considred Kotlin/Native and actaullay for iOS is still beta but for Desktop app (Linux, windows and MAC) it's stable
n
oh really? do you have any document links guidance on that?
sorry i thought i past it
checkout supported platform
for learning purposes i once tried CMP to make mac app actually
m
You need to write a JVM app for this then use JNI or Panama to call native APIs
or into your own C++ which then calls the APIs
n
yeah, I followed the Kotlin Multiplatform wizard to create my app and selected the Desktop target as well. However, problem is, when I write code using actual/expect, it will use the JVM actual implementation
@mikehearn yeah, thank you. I think so too
m
Correct. Expect/Actual is irrelevant for this use case unless you target mobile also
n
alright, thanks guys! c++ here I come
m
Also check out Panama and jextract. It makes calling into C based APIs like Win32 easier. There's an equivalent for Objective-C I think
n
could you please share the link to the repository please. Much appreciated. I searched for those but got weird result
oh I see, its name is
Panama and jextract
not Panama or jextract
😄
m
The jextract tool generates Java files for calling into C functions. Unfortunately it can't do C++