jni.h提供了这一点
struct JNINativeInterface_ {
...
jint (JNICALL *GetVersion)(JNIEnv *env);
...
}要在C中调用它,可以编写为
void test(JNIEnv *env){
// C
jint version = (*env)->GetVersion(env);
// C++
// jint version = env->GetVersion();
}那我怎么才能在kotlin中做到呢?
fun test(env: CPointer<JNIEnvVar>){
val version = // how?
}在谷歌搜索答案后,用JNI搜索Kotlin/Native的例子很少,但它们只是基本的例子,请帮助。
提前谢谢。
发布于 2020-12-01 21:12:35
感谢迈克尔。
长长的答案是
fun test(env: CPointer<JNIEnvVar>){
// getting "JNINativeInterface_" reference from CPointer<JNIEnvVar> by
val jni:JNINativeInterface_ = env.pointed.pointed!!
// get function reference from JNINativeInterface_
// IntelliJ can help to find existing methods
val func = jni.GetVersion!!
// call a function
var version = func.invoke(env)
// above expression can be simplify as
version = env.pointed.pointed!!.GetVersion!!(env)!!
}希望这能帮助人们理解Kotlin/原生?。
https://stackoverflow.com/questions/65075020
复制相似问题