Does anyone know of any examples of a multiplatfor...
# multiplatform
a
Does anyone know of any examples of a multiplatform project that demonstrates a not-fully KMP Windows project? I think I'm looking for something that • defines some shared KMP modules using the standard lib, and maybe multiplatform-friendly libs like SQLDelight, Ktor, kotlinx.serialization, etc • compiles the shared KMP code to a library (I think DLL is the right format?) • Consumes that library from a C# Windows application with some reasonable type definitions • Ideally ◦ has some reasonable type definitions that are generated for the methods ◦ supports some sort of interop for things like Coroutines/Flow (maybe something that could be added to KMP-NativeCoroutines?) I’ve seen plenty of examples that are built in full Compose Multiplatform that also happen to support Windows, but I’m looking for something similar to the story that KMP has for integrating with brownfield Android and iOS apps
t
I have experimented with a specific approach, and here are my insights: 1. Initially, I attempted to use mingwx64 with a C# WinUI3 Application. While mingwx64 successfully exports DLLs and .h headers, integrating these directly into C# is challenging due to the lack of a straightforward method for calling C functions. This typically necessitates code generation tools to create C# P/Invoke methods from .h files, a daunting task with extensive headers (over 10,000 lines). I experimented with Cysharp csbindgen, which was effective, but introduced multiple conversion layers (Kotlin -> C Header -> P/Invoke). This process can lead to significant loss of methods/information, and troubleshooting conversion errors can be difficult. 2. To streamline the process, I explored mingwx64 in conjunction with a C++ WinUI3 Application. This approach proved functional but introduced complexity due to the prevalence of pointers, particularly for functions with generic return types. Writing wrappers for these functions was cumbersome, and many classes were not readily available in the mingwx64 headers, requiring additional manual effort. 3. Consequently, I considered using ikvm.net. Integrating a fat jar with ikvm and a C# WinUI3 Application yielded excellent results. This setup allowed direct use of Kotlin classes and functions in C#, with the sole exception being the conversion of 'suspend' to 'Task'. However, ikvm is limited to JDK 8 support. While this is currently manageable, it could pose challenges as more libraries transition to JDK 11. Attempts to use bsideup's Jabel for converting JDK 11 jars to JDK 8 were unsuccessful.
🤩 1
thank you color 1
👍 1
a
Thanks for sharing! Super useful to have this context