I am trying to solve a Cocos2d-x Keyboard input crash on Android 5.x when I create CCImage from the text with many emoji found on the keyboard (some work though, but most don't.) On Android 4.x several of the devices just display mangled text/extra characters. The source of the crash is the JNI's NewStringUTF() call. It simply does not support all of the 2, 3 and 4 byte utf-8 characters in Android 5/Lollipop.
This crash happens on cocos2d-x v2.2.6 (and confirmed on 3.x) using NDK 10e with Toolchain 4.8 (not sure if any of that makes too much of a difference, we were using 9d prior to moving to Android Studio and I am certain we had this issue, but there was much less usage to lollipop.)
If you never push any of non-modified utf-8 symbols (i.e. stick to ascii) you'll probably never see the issue.
Log Cat:
12-11 01:02:17.460 10451-10959/com.appsomniacs.da2.debug A/art: sart/runtime/check_jni.cc:65] string: '
We found a solution by sending the contents of the std::string in jbyte array and let the java side be java and return the jstring we could use on the C++ jni side. For us these strings are coming from the users keyboard and I have 170k crashes in one week that says they use emoji in character names and chat like crazy... and naming their avatars in itself caused crashes too. So any lobby a Android 5.x user joined would cause them to crash as soon as their client tried to render the other players names with the characters in question. In Android 4.x this was not an issue in that it just printed some garbage characters.
In your c++ side you can do something like this to achieve this function:
On the java side turn that into a java string and return it in the same method:
In our case we wanted a jstring (which is inputed as modified UTF8) to feed to the rendering side and store for retrieval later, returning an empty string was just a choice we made to clue us in conversion failed.
I hope this helps someone find a way... maybe even the right way...