我用 jni 开发了一个 android 应用程序。 我在 GetStringUTFChars 的 dvmDecodeIndirectRef 中得到了一个 dvmabort。 我只中止了一次。
为什么会这样? 如何解决?
如果有人知道要点,请教我。
抱歉,信息不足。
这是我的代码。
std::string toStdStr(JNIEnv* env, jstring jstr)
{
const char* chars = env->GetStringUTFChars(jstr, 0); //<-dvmAbort
std::string stdstr;
if( NULL==chars ) {
stdstr = "";
}else{
stdstr = std::string(chars );
env->ReleaseStringUTFChars(jstr, chars );
}
return stdstr;
}
下面是 nkd-stack 故障转储。
我用xxxxxxxx覆盖了隐私信息
********** Crash dump: **********
Build fingerprint: 'xxxxxxxx'
pid: xxxxxxxx, tid: xxxxxxxx, name: Thread-78 >>> xxxxxxxx <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Stack frame #00 pc xxxxxxxx /system/lib/libc.so (tgkill+12)
Stack frame #01 pc xxxxxxxx /system/lib/libc.so (pthread_kill+48)
Stack frame #02 pc xxxxxxxx /system/lib/libc.so (raise+10)
Stack frame #03 pc xxxxxxxx /system/lib/libc.so
Stack frame #04 pc xxxxxxxx /system/lib/libc.so (abort+4)
Stack frame #05 pc xxxxxxxx /system/lib/libdvm.so (dvmAbort+78)
Stack frame #06 pc xxxxxxxx /system/lib/libdvm.so (dvmDecodeIndirectRef(Thread*, _jobject*)+146)
Stack frame #07 pc xxxxxxxx /system/lib/libdvm.so
Stack frame #08 pc xxxxxxxx /system/vendor/lib/libxxxxxxxx.so toStdStr(_JNIEnv*, _jstring*)+56): Routine _JNIEnv::GetStringUTFChars(_jstring*, unsigned char*) at /home/softdev/opt/android-ndk-r9d/platforms/android-19/arch-arm/usr/include/jni.h:879
...
谢谢!
2015/04/30 添加后记
我发现在 jni.cpp 的第 365 行的 ReportJniError 中调用了 abort。
Cross Reference: /dalvik/vm/Jni.cpp
这是默认路径。 什么时候发生? 来这里有什么条件?
最佳答案
这意味着 jstr
在传递给 toStdStr
时无效。尝试 env->CreateGlobalRef(jstr)
before toStdStr
调用。不要忘记发布全局引用。
关于android - GetStringUTFChars 中的 dvmDecodeIndirectRef 中的 dvmAbort,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29822236/