我正在使用 C++ 开发一个 Android 应用程序。
当我尝试在其中创建public native String HelloJNI()
时MainActivity.java
显示此错误:
报告 java 中的本地方法声明,其中在项目中找不到相应的 JNI 方法
我正在使用 C++ 开发一个 Android 应用程序。
当我尝试在其中创建public native String HelloJNI()
时MainActivity.java
显示此错误:
报告 java 中的本地方法声明,其中在项目中找不到相应的 JNI 方法
It's because Android Studio (well Lint actually) doesn't find a C++ function defined in your project that implement the one you declare here.
Declare a C++ function to implement your function definition ("public native String HelloJNI()"), something like that:
JNIEXPORT jstring JNICALL Java_your_package_name_ MainActivity_ HelloJNI(JNIEnv * env, jobject obj)
{
/* Your code here */
return env->NewStringUTF("Your return value");
}
Solution 2: Click on your function name in your declaration, wait for the "red bulb" to show, click on the red bulb and select "Create function xxx", it should create the stub method I put above automatically on your C++ file for you.