Curious question about Skiko implementation: Why t...
# compose-desktop
s
Curious question about Skiko implementation: Why the JNI implementation is written in C++ and not exposed by Kotlin Native? I saw couple examples using KN for JNI. I'm looking to understand that because I'm starting a library multiplatform that will require JNI for JVM.
g
Why the JNI implementation is written in C++ and not exposed by Kotlin Native
There is no interopability between K/N and JVM, so it still require JNI (or similar mechanisms) as with any other native API
It was requested, to have an interop between K/N and JVM but there are no short plans for this
s
I mean something like this:
Copy code
@CName("Java_org_jonnyzzz_jni_java_NativeHost_callInt")
fun callInt(env: CPointer<JNIEnvVar>, clazz: jclass, it: jint): jint {
  initRuntimeIfNeeded()
  Platform.isMemoryLeakCheckerActive = false

  println("Native function is executed with: $it")
  return it + 1
}
From: https://jonnyzzz.com/blog/2019/12/15/jni-kotlin/ Hopefully in short future we have KN/JVM interop because would be a big plus for native libraries, specially desktop ones that most of the code is Native libraries
g
Hopefully in short future
I’m very doubt about this. Though I would love to see such feature
I mean something like this:
This is not a JNI per se, this is essentially exposing K/N API as C API
a
Skia is an external library which is written in C++. What's the point of using K/N given that it adds K/N-C++ interop?
g
I really doubt about direct C++ interop
but it’s easy to expose C++ API as C API which is what many C libraries are doing and K/N already can work with C and expose own API as C API
so if K/N would provide some inerop tool for JVM, it could just generate JNI for easy interop between K/N and K/JVM
Now to interop between K/N and K/JVM you have to write JNI manually or use tool which does this for you
a
Yeah that's the case when the native part is also written in K/N. However skia is written in C++ so calling C++ in K/N (or creating C API for the whole library) doesn't seem a good choice.
g
Yep, you right
But K/N anyway need interop with Skia, so you anyway need C to work with it
Also I believe there is experimental C API in Skia
But even withotu C API, you can write C++ code which wraps C++ API and exposes own C API for parts which you need
s
Skiko in KN was access to Skia, evev if they use C++ to expose C to KN (I don't know if this is the case) they also have JNi binding, só you have both, this is what I struggling here. Why do both what are the benefits or the issues with using KN for JNI as well
g
JNI binding is used by K/JVM to work with Skia
Skiko is MP library, it provides implementation not only for native but also for JVM