I have a method in JNI C/C++ which takes jstring and returns back jstring some thing like as below,
NATIVE_CALL(jstring, method)(JNIEnv * env, jobject obj
I also struggled with the same problem from the last day. Finally figured out a solution after a day .. I hope this reply may save someone's day..
The problem was I was calling another function within the native function, used the returned string directly and which caused crash in android older versions
So firstly I saved the string returned from another function to a variable then used it, and the problem gone :D
The below example may clear your concept
//older code with error
//here key_ is the string from java code
const char *key = env->GetStringUTFChars(key_, 0);
const char *keyx = getkey(key).c_str();
return env->NewStringUTF(keyx);
And here is how I solved this error
//newer code which is working
//here key_ is the string from java code
const char *key = env->GetStringUTFChars(key_, 0);
string k = getkey(key);
const char *keyx = k.c_str();
return env->NewStringUTF(keyx);
Happy coding :D