I have import and tested this project:
https://github.com/android/ndk-samples/tree/master/hello-jni
in Android Studio and worked well.
But when I copy the code for another new project I have the follow error:
“Incompatible point types jclass
and `jobject”
In this line:
g_ctx.mainActivityClz = (*env).NewGlobalRef(clz);
Is it not possible to use “NewGlobalRef” to create a new reference for a class in more recent versions?
NewGlobalRef
always returns a jobject
even though you're giving it a jclass
(which is a subclass of jobject
).
You can solve this warning by explicitly downcasting to jclass
, either as
(jclass)env->NewGlobalRef(...)
or
static_cast<jclass>(env->NewGlobalRef(...)