Why "java.lang.NoSuchMethodError: no static method" from (JNIenv*)->GetStaticMethodID?

Why "java.lang.NoSuchMethodError: no static method" from (JNIenv*)->GetStaticMethodID?

我的 Android NDK 项目的 Java 代码调用 C++ 函数,

    extern "C" JNIEXPORT jstring JNICALL Java_com_crimson_tub_MainActivity_stringFromJNI(JNIEnv *env, jobject jo)

我要打电话给

    public static void requestPermissions(@NonNull final Activity activity, @NonNull final String[] permissions, @IntRange(from = 0L) final int requestCode) 

在 Android 文档中找到:

https://developer.android.com/reference/android/support/v4/app/ActivityCompat.html#requestPermissions(android.app.Activity, java.lang.String[], int)

我已经尝试了几个我认为有问题的代码变体,

jmethodID jmid = env->GetStaticMethodID(clzz,"requestPermissions", "(Landroid/app/Activity;[Ljava/lang/String;I)V;"),
//jmethodID jmid = env->GetStaticMethodID(clzz,"requestPermissions", "(Lcom/company/project/MainActivity;[Ljava/lang/String;I)V;"),
  //jmethodID jmid = env->GetStaticMethodID(clzz,"requestPermissions", "(Ljava/lang/Object;[Ljava/lang/String;I)V;"),

以上所有选项都会导致相同的异常,

    No pending exception expected: java.lang.NoSuchMethodError: no static method "Landroid/support/v4/app/ActivityCompat;.requestPermissions(Landroid/app/Activity;[Ljava/lang/String;I)V;"

c++代码,

    extern "C" JNIEXPORT jstring JNICALL
    Java_com_crimson_tub_MainActivity_stringFromJNI(JNIEnv *env,jobject jo) {

        std::string hello;

        jobjectArray ret;
        int i;

        char *data[2]= { "android.permission.CAMERA" ,
                 "android.permission-group.CALENDAR"};

        ret= (jobjectArray)env->NewObjectArray(2,env->FindClass("java/lang/String"),env->NewStringUTF(""));

        for(i=0;i<2;i++) env->SetObjectArrayElement(ret,i,env->NewStringUTF(data[i]));

        jint result = 0xffffffff;

        jclass clzz = env->FindClass("android/support/v4/app/ActivityCompat");
        if (!clzz){
            hello += "-class";
        }else{
            hello += "+class";
        }

        jmethodID jmid = env->GetStaticMethodID(clzz,"requestPermissions", "(Landroid/app/Activity;[Ljava/lang/String;I)V;"),
        //jmethodID jmid = env->GetStaticMethodID(clzz,"requestPermissions", "(Lcom/company/project/MainActivity;[Ljava/lang/String;I)V;"),
          //jmethodID jmid = env->GetStaticMethodID(clzz,"requestPermissions", "(Ljava/lang/Object;[Ljava/lang/String;I)V;"),

        env->CallStaticVoidMethod(clzz,jmid,jo,ret,result);

        env->DeleteGlobalRef(jo);
        return env->NewStringUTF(hello.c_str());

    }

我希望能够通过 JNI 调用 Android Java 函数,

    ActivityCompat.requestPermissions 

直接来自 C++,所以稍后我可以从我的项目中删除 Java 代码。

我已经在这个问题上工作了一段时间,但仍然没有成功。

感谢所有的帮助,非常感谢。

谢谢大家

问题是;在签名中的 V 之后。现在可以了。哈哈。