简体   繁体   中英

Android JNI call method GetStringUTFLength getting crash

Code

std::string abc(const char* param)
{
    JNIEnv *pJNIEnv = GetJNIEnv();

    //TODO : for testing
    jstring jstr = pJNIEnv->NewStringUTF("Ñandú");  //can pass param also
    std::string result = convertJStringToString(pJNIEnv, jstr);


    return result;
}


std::string convertJStringToString(JNIEnv *env, jstring str) {
    const jsize len = env->GetStringUTFLength(str);
    const char *strChars = env->GetStringUTFChars(str, (jboolean *) 0);
    std::string Result(strChars, len);
    env->ReleaseStringUTFChars(str, strChars);
    return Result;
}

Getting Crash report on Play Store

pid: 0, tid: 0 >>> x.abc.xyz <<<

backtrace:
  #00  pc 0000000000071914  /system/lib64/libc.so (tgkill+8)
  #01  pc 000000000001e058  /system/lib64/libc.so (abort+88)
  #02  pc 0000000000456740  /system/lib64/libart.so (_ZN3art7Runtime5AbortEPKc+528)
  #03  pc 0000000000456eb8  /system/lib64/libart.so (_ZN3art7Runtime7AborterEPKc+24)
  #04  pc 000000000054a840  /system/lib64/libart.so (_ZN7android4base10LogMessageD1Ev+912)
  #05  pc 00000000002e6534  /system/lib64/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1732)
  #06  pc 00000000002e683c  /system/lib64/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+204)
  #07  pc 0000000000363b30  /system/lib64/libart.so (_ZN3art3JNI18GetStringUTFLengthEP7_JNIEnvP8_jstring+816)
  #08  pc 00000000001e205c  /data/app/x.abc.xyz-Sor8tcKXEtf7w-3TH6bZFw==/lib/arm64/libnative-lib.so (_Z22convertJStringToStringP7_JNIEnvP8_jstring+44)

Unable to understand why this is crash, Mostly crash on Android 8.0. Please don't say pass jstring value NULL is the reason that's I already checked in my code before passing jstring to this method.

I had similar problem on Xiami phone. It was problem with formatting string, before native stacktrace, I've got following error:

2020-07-28 10:35:51.321 6978-6978/cookbook.chapter2 A/okbook.chapter: art_method.cc:530] Check failed: found_virtual Didn't find oat method index for virtual method: int android.icu.text.DecimalFormat_ICU58_Android.getMinimumIntegerDigits()

Problematic code was formatting string(precisely last argument of string formatting):

__android_log_print(ANDROID_LOG_INFO, "native", "UTF-8 string with Chinese characters: %s, string length (number of bytes) %d=%d", newStr, newStrLen, strlen(newStr));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM