Gavin Ray
10/12/2021, 2:42 PMJava_org_jetbrains_skija_Canvas__1nDrawPicture
without (what looks like) passing any JNIEnv
🤔alexander.gorshenev
10/12/2021, 3:31 PMGavin Ray
10/12/2021, 3:36 PMJNIEnv*
pointer for kref __Kinstance
olonho
10/12/2021, 3:38 PMGavin Ray
10/12/2021, 3:38 PMtechnically Skiko is an approach to multiplatform native interop for all major Kotlin targetsI am hoping for a not-so-distant future in which Skiko is used as the rendering backend for Compose on iOS. Then you can use a single Kotlin codebase and UI framework to build experiences across all targets -- even the browser! Unfortunately, it seems the KN part of Skiko is fairly young, was only MacOS supported until recently, now there is at least a Linux OpenGL renderer. Though it a stub for now
Gavin Ray
10/12/2021, 3:41 PMGavin Ray
10/12/2021, 3:42 PMxamarin-mobile-bindings
branch which has the C ABI that Microsoft uses, and then generate Kotlin Native interop types from it and experiment with that. Would maybe save a lot of effort.olonho
10/12/2021, 3:43 PMGavin Ray
10/12/2021, 3:44 PMsmallshen
10/14/2021, 4:44 AMmemScoped {
val mP = alloc<JNINativeMethod> {
name = methodName.cstr.ptr
signature = descriptor.cstr.ptr
fnPtr = m // native function pointer
}
env.pointed.pointed!!.RegisterNatives!!(env, findClass(className), mP.ptr, 1)
}
The native function pointer can used as
staticCFunction<CPointer<JNIEnvVar>, jobject, jdouble> { env, t, ->
// same as fun yourMethod(env: CPointer<JNIEnvVar>, obj: jobject) : jdouble
// jdouble is a primitive, cinterop will make typealias points to kotlin.Double, the result can't be null
}
smallshen
10/14/2021, 4:48 AMGavin Ray
10/14/2021, 4:41 PMThe way I use in my own project is to useto generate classes that every method is export and use it on kotlin JVM, and create other sets of native platforms which are going to be used by JNI, using JNI in kotlin native is simple,ksp
support it.cinterop
For link the native method to JVM, you can simply use@CName("Java_org_jetbrains_skiko_blablabla")
or through JNI methodThis is a really clever approach @smallshen!
Gavin Ray
10/14/2021, 4:45 PMmemScoped {
val mP = alloc<JNINativeMethod> {
name = methodName.cstr.ptr
signature = descriptor.cstr.ptr
fnPtr = m // native function pointer
}
env.pointed.pointed!!.RegisterNatives!!(env, findClass(className), mP.ptr, 1)
}
Do I understand right, that this snippet of code says?
• Allocate a value, mP
, of type JNINativeMethod
where:
◦ The name
= the Kotlin Native method's name, as a cstr*
◦ The signature
= the Kotlin Native method's descriptor, as a cstr*
◦ The fnPtr
itself = m
, which points to the Kotlin Native function
• Then, register a new JNI method in the JNIEnv
natives from this KN definitionGavin Ray
10/14/2021, 4:47 PMsmallshen
10/14/2021, 4:56 PM