aj
02/09/2024, 11:54 PMKaMPKit
prototype project that uses libcurl (or any simple C/C++ library) to show case talking to a native library from KMM project.LewsTherinTelescope
02/10/2024, 1:43 AMkpgalligan
02/12/2024, 3:37 PMkpgalligan
02/12/2024, 3:40 PMkpgalligan
02/12/2024, 3:41 PMkpgalligan
02/12/2024, 3:42 PMaj
02/13/2024, 12:58 AMkpgalligan
02/13/2024, 2:23 PMaj
02/13/2024, 2:24 PMaj
02/13/2024, 2:29 PMaj
02/13/2024, 2:30 PMkpgalligan
02/13/2024, 2:36 PMplatform built static .a libs for both android and iOS.a libs of libcurl or your Kotlin code? Might be easier to comment if you have a public repo to look at.
aj
02/13/2024, 2:43 PMprintHelloWorld()
C function. The simplest possible ever example.
Nothing related to libcurl, I was just trying to use it as a reference since nothing simpler than that that might be related.
My problem is creating a project with shared code calling the printHelloWorld() function from both Android/iOS.kpgalligan
02/13/2024, 3:50 PMandroidMain
Kotlin code), configure JNI and (I would assume) the NDK to build your printHelloWorld()
code. Once your Android/NDK code is working correctly, you should be able to call printHelloWorld()
from Android-specific Kotlin code (in androidMain
). To be clear, none of that is "KMP". You would code that the same if you had a strictly Android project.
When that's working, you'll need to config cinterop on iOS. cinterop will need the .h
file for printHelloWorld()
. That will generate the Kotlin definitions with which you can call the function from iosMain
. As in the video, you also need to figure out how to package that compiled binary.
When both android and iOS are working, then you can write commonMain
code that delegates to each platform's implementation.
I'm guessing that didn't clear things up too much. There's a lot to figure out in there. The big-picture thing to understand is that native C integrations require implementations on both Android and iOS separately. That means you need to set up the JNI on Android, the cinterop on iOS. The actual "shared code" is manually written in commonMain
and delegates to each platform for implementation.
There's no auto-gen for code that allows KMP to talk to C across platforms. People have discussed it, but it wouldn't be trivial to build, to put it mildly.aj
02/15/2024, 4:45 PMkpgalligan
02/15/2024, 5:09 PM