0

I'm developing an Android app using C++.

When I try to create public native String HelloJNI() in MainActivity.java it's showing this error:

Reports native method declaration in java where no corresponding JNI method found in project

vikas
  • 1
  • 2

1 Answers1

0

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.

Sistr
  • 1,175
  • 10
  • 26