Hey everyone, how can we build native WIndows Apps...
# multiplatform
s
Hey everyone, how can we build native WIndows Apps with the help of Kotlin Multiplatform? I know we generally use Compose Desktop for the UI but that is still a JVM application, right? Isn't it different from building native Windows apps? And if it is possible, is there a UI framework for that? I'm expecting to use frameworks like WinUI3 but afaik, it's written in C#
j
I don’t know anything about calling C# APIs from Kotlin, however you can perfectly write your business code in Kotlin, build it as a DLL, build your UI using C# with the framework you want, then use the DLL from the C# code.
v
If you want Kotlin without the JVM you will likely end up using Kotlin Native. It has some tools like
cinterop
that can be used to call native API's from Kotlin. Right now it only supports native libraries that expose C headers so your options for available platform frameworks are limited.
Me and some others are working on making GTK work for Kotlin Native, while that isn't exactly a "windows native" GUI toolkit, I am very hopeful for the project and I think we will have a good Kotlin Native GUI solution for Linux/Windows/MacOS in the near future.
K 1
s
That would be awesome to see! Thank you for working on it.. very hopeful for it 🤞K
s
What do you want to achieve here? Do you want to use Windows only APIs in your application? Compose Desktop can generate pretty good installer for Windows, Mac and Linux. The JVM is built in this installer, the user don’t even know that the API is JVM based. This means that for example, the user downloading your application does not need to have JVM installed in the machine… For windows only APIs, there is Open Source libraries, JNI, JNA.
v
I'm not OP but I can see use cases for Kotlin/Native applications that don't require a JVM to run. Why would I bring in a full (or stripped down) JVM if most of the application code is Kotlin/Native and all the JVM does is provide a bridging layer to other native platform API's through JNI/JNA?
s
To be fair, this wasn't a practical question from my end. I was just curious to know that since KMP theoretically supports so many platforms on a native level, do we also have any arrangements to write their Native UI as well? I agree that JVM can produce very good output, but from what I understand, KMP's base idea was to NOT share the UI layer but everything else besides it (and we're essentially doing that only by using Compose for everything, this is exactly what Flutter is doing as well). And in order to get the native look and feel, it's generally the best idea to use the native framework only. That's why I was wondering if we could somehow achieve interop between Kotlin and C# Windows Application code?
v
It looks like there are some solutions to export methods from a C# codebase as C functions. So in theory you could then use cinterop to call this C function from KN. https://stackoverflow.com/a/6795403
so if the native API's you want are available in C#, you could write a small C# shim that exports to C. It will probably be a ton of work if you have a big API surface to cover.
s
That seems fair for now, will have a look at it. Thanks to everyone who commented on this thread and gave their inputs 🙌
591 Views