Bad JNI version returned from JNI_OnLoad解决

今天写了个android jni app,我的JNI_OnLoad是这么写的:

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv* env = NULL;
    jint result = -1;

    if((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_1) != JNI_OK)
    {
        return -1;
    }

    if(env == NULL)
    {
        return -1;
    }

    if(!registerNatives(env))
    {
        return -1;
    }

    return JNI_VERSION_1_1;
}
结果运行后,很简单的代码却出错,查看错误信息为:

java.lang.UnsatisfiedLinkError: Bad JNI version returned from JNI_OnLoad in "/data/app/**.apk/lib/arm64/libsafe.so"

上androidxref查JNI_CreateJavaVM源码可知

android 1.6~4.3 version >= JNI_VERSION_1_2合法

android 4.4~7.1 version == JNI_VERSION_1_2 | JNI_VERSION_1_4 | JNI_VERSION_1_6


从历史急角度看,选用最新JNI版本最合适

 
  

你可能感兴趣的:(Bad JNI version returned from JNI_OnLoad解决)