流程是在 cpp 中调用 jni.cpp 再调用 java,报错
JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]]
下面贴一下调用代码
//通过 jvm 获取 env 的方式
JNIEnv *get_env(int *attach) {
if (javaVM == NULL) return NULL;
*attach = 0;
JNIEnv *jni_env = NULL;
int status = javaVM->GetEnv((void **) &jni_env, JNI_VERSION_1_6);
if (status == JNI_EDETACHED || jni_env == NULL) {
JavaVMAttachArgs vmAttachArgs;
vmAttachArgs.version = JNI_VERSION_1_6;
vmAttachArgs.name = NULL;
vmAttachArgs.group = NULL;
status = javaVM->AttachCurrentThread(&jni_env, &vmAttachArgs);
if (status < 0) {
jni_env = NULL;
} else {
*attach = 1;
}
}
return jni_env;
}
//对应 java 文件声明的 native 函数
extern "C"
JNIEXPORT void JNICALL
Java_com_hik_netsdk_SimpleDemo_XJni_Heart(JNIEnv *ev, jobject t) {
int attach = 0;
JNIEnv *env = get_env(&attach);
const char *javaPath="包名 /XJni";
jclass clazz = env->FindClass(javaPath); //debug 显示返回为 null
jmethodID mid = env->GetMethodID(clazz, "CallJavaHeart", "()V");
jobject jobject = env->AllocObject(clazz);
env->CallVoidMethod(jobject, mid);
if (attach == 1) {
del_env();
}
}
网上的一些解决方案试过了,但是无效,希望有大佬可以帮忙看看,非常感激