对于使用Kotlin的方法,jmethodID为NULL

时间:2018-01-15 20:08:16

标签: android c++ java-native-interface kotlin native

我正在使用本机库,即使该方法存在,也会出现以下异常。我有一个nativeInit函数,也导出到MapController,它按预期工作。但是,nativeLoadScene方法会导致错误。

JNI DETECTED ERROR IN APPLICATION: jmethodID was NULL
    in call to CallObjectMethodV
    from int com.demo.lib.MyController.nativeLoadScene(long, java.lang.String, java.lang.String[])

JNI方法

JNIEXPORT jint JNICALL Java_com_demo_lib_MyController_nativeInit(JNIEnv *jniEnv, jobject obj, jobject tangramInstance, jobject assetManager) {
   ...
}

JNIEXPORT jint JNICALL Java_com_demo_lib_MyController_nativeLoadScene(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jstring path, jobjectArray updateStrings) {
   ...
}

com.demo.lib.MyController.kt

companion object {
    init {
        System.loadLibrary("c++_shared")
    }
}

// this works
external fun nativeInit(instance: MapController, assetManager: AssetManager?): Long

// this gives error
external fun nativeLoadScene(mapPtr: Long, path: String, updateStrings: Array<String?>?): Int

0 个答案:

没有答案