How to access a C++ method from a static method of Java/Kotlin.
When i try to access it. I'm getting this error.
"Non-static 'stringFromJNI()' cannot be referenced from a static context"
JNIHelper.kt :
object JNIHelper {
external fun stringFromJNI(): String
init {
System.loadLibrary("native-lib")
}
}
native-lib.cpp :
extern "C" JNIEXPORT jstring JNICALL
Java_com_my_package_JNIHelper_stringFromJNI( //Test
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
Sample.Java :
private static Data getData(Context context) {
return JNIHelper.stringFromJNI(); //Here i get Compilation error
}