Android ICS 4.0 NDK NewStringUTF is crashing down the App

前端 未结 10 1989
长情又很酷
长情又很酷 2020-12-02 15:01

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         


        
10条回答
  •  情书的邮戳
    2020-12-02 15:33

    In my opinion, its not a bug.

    NewStringUTF Constructs a new java.lang.String object from an array of characters in modified UTF-8 encoding.

    Modified UTF-8 is not standard UTF-8. See Modified UTF-8

    In most cases, UTF-8 encoded string is valid Modified UTF-8. Because Modified UTF-8 and UTF-8 are quite similar. However when it comes to Unicode string beyond Basic Multilingual Plane, they are not compatible.

    Solution: pass UTF-8 bytes to Java layer and new String(bytes, "UTF-8") then pass jstring to JNI.

提交回复
热议问题