android JNI 报告找不到方法

android JNI report can't find method

我使用以下代码包装所有本机函数

package com.user.game;

import android.content.res.AssetManager;

public class MyGLRenderer {

    static {
        System.loadLibrary("Engine");
    }

    public static native void passAssetManager(AssetManager assetManager);
    public static native void getAppDirectory(String dir);
    public static native void setExternalDirectory(String dir);
    public static native void pointerLeave(int id, float x, float y);

}

我使用 C++ 中的以下内容

JavaVM* javaVM = NULL;

jint JNI_OnLoad(JavaVM *vm, void *reserved) {
    javaVM = vm;
    return JNI_VERSION_1_6;
}

bool call_Java_checkStoragePermission() {
    JNIEnv *env;
    bool shouldDetach = false;
    static jclass javaClassRef = NULL;
    static jmethodID javaMethodRef = NULL;
    static bool once = true;

    if (javaVM->GetEnv((void **)&env, JNI_VERSION_1_6) == JNI_EDETACHED) {
        shouldDetach = true;
        javaVM->AttachCurrentThread(&env, NULL);
    }

    if (once) {
        jclass dataClass = javaClassRef = env->FindClass("com/quetzalfir/polygondash/Game_Activity");
        if (checkExcp(env, "findclass")) {
            return false;
        }

        javaClassRef = (jclass) env->NewGlobalRef(dataClass);
        if (checkExcp(env, "newGlobalRef")) {
            return false;
        }

        //BEFORE EDIT: this was env->GetMethodID();
        javaMethodRef = env->GetStaticMethodID(javaClassRef, "checkStoragePermission", "()Z");
        if (checkExcp(env, "get methodID")) {
            return false;
        }

        once = false;
    }

    jboolean ans = env->CallStaticBooleanMethod(javaClassRef, javaMethodRef);

    if (shouldDetach) {
        javaVM->DetachCurrentThread();
    }

    return ans;
}

bool checkExcp(JNIEnv *env, const char *str) {
    if (env->ExceptionCheck()) {
        SFLOGI("JNI: error %s",str);
        jthrowable flag = env->ExceptionOccurred();
        env->ExceptionClear();
        env->Throw(flag);

        return true;
    }

    return false;
}

我从我的主 activity 调用包装器 class,它是

package com.user.game;

public class Game_Activity extends Activity {
    private static String TAG = "Debugging";

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        MyGLRenderer.getAppDirectory(getExternalFilesDir(null).getAbsolutePath());
        MyGLRenderer.setExternalDirectory(Environment.getExternalStorageDirectory().getPath());

        MyGLRenderer.passAssetManager(getAssets());
    }

    public static boolean checkStoragePermission() { //before edit Boolean

        Log.w(TAG, "calling...........");

        return true;
    }

}

但是当我调用 call_Java_checkStoragePermission() 时出现以下错误

10-09 16:34:48.502 18590-18590/com.user.game D/dalvikvm: GetMethodID: not returning static method Lcom/user/game/Game_Activity;.checkStoragePermission ()Z
10-09 01:15:17.081 14171-14171/com.user.game I/Debugging: JNI: error get methodID
10-09 01:15:17.081 14171-14171/com.user.game I/Debugging: bool = 0
10-09 01:15:17.081 14171-14171/com.user.game E/InputEventReceiver: Exception dispatching input event.
10-09 01:15:17.081 14171-14171/com.user.game E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
10-09 01:15:17.091 14171-14171/com.user.game E/MessageQueue-JNI: java.lang.NoSuchMethodError: no method with name='checkStoragePermission' signature='()Z' in class Lcom/user/game/Game_Activity;
                                                                                  at com.user.game.MyGLRenderer.pointerLeave(Native Method)

有人可以帮助我吗?

对静态函数使用GetStaticMethodId

jmethodID javaMethodRef = env->GetStaticMethodID(javaClassRef, "checkStoragePermission", "()Z");