The JNI example of the Android NDK band is using C to define the JNI interface, but in the project, because the native code is written in C + +, I use C + + to define the JNI interface, but beginners always encounter many problems:
Frequently asked questions in JNI:
1, base operand of ' has non-pointer type ' jnienv {aka _jnienv} ' and method ' Getstringutfchars ' could not being resolved
One of the problems with your JNI configuration is whether. cpp or. c Files and:
And
Solution to the problem:
1 "with C + + to write code, the file name must be" cpp "suffix:C + + code must has a. cpp extension., must be CPP suffix, C suffix does not work;2 "Use C to write code, the file name must be" C "suffix;
2. The code that is called is written like this://return (*env)->newstringutf (env, "Hello from JNI!"); /If it is in C language format, this way
//return Env->newstringutf ((char *) "Hello from JNI!"); /c++ in this format
The wrong way:
Online there is a method is as follows, but this method is obviously cheating children, which is useful to ignore this kind of thing, not recommended
The right approach:
The problem is 2nd above, so
This is if you want to delve into the reasons you can view <jni.h>
1. Using the. cpp file to define the
Const char* Getstringutfchars (jstring string, jboolean* iscopy)
{return Functions->getstringutfchars (this, string, iscopy);}
2. Definition with. c file
Const char* (*getstringutfchars) (jnienv*, jstring, jboolean*);
Base operand of ' a ' has non-pointer type ' jnienv {aka _jnienv} ' and method ' Getstringutfchars ' could no