简体   繁体   English

JNI。 不同Android OS版本之间的不同行为

[英]JNI. different behavior between different Android OS versions

my application runs following code : 我的应用运行以下代码:

void BmrDeviceInfo_convertToC(JNIEnv *pEnv, jobject jBmrDeviceInfo, BmrDeviceInfo& cBmrDeviceInfo){

__android_log_print(ANDROID_LOG_INFO, "BEAMER_JNI", "g_classBmrDeviceInfo is = %s", (g_classBmrDeviceInfo == NULL) ? "NULL" : "OK"); //g_classBmrDeviceInfo is initialize on JNI_OnLoad

jfieldID fieldName = pEnv->GetFieldID(g_classBmrDeviceInfo, "m_strName", "Ljava/lang/String;"); // OK for Android 4.2 and crash for Android 3.1 or less

..................................
}

And LogCat output for crash case: 和崩溃案例的LogCat输出:

04-17 16:28:44.118: I/BEAMER_JNI(446): g_classBmrDeviceInfo is = OK
04-17 16:28:44.118: W/dalvikvm(446): JNI WARNING: 0x4053dc70 is not a valid JNI reference
04-17 16:28:44.118: W/dalvikvm(446):              in Lcom/xxxxxxx/xxxxxx/controller/CoreController;.Init (Lcom/xxxxxxx/xxxxxx/listviews/DeviceInfo;Ljava/lang/String;)I (GetFieldID)
04-17 16:28:44.118: I/dalvikvm(446): "main" prio=5 tid=1 RUNNABLE
04-17 16:28:44.118: I/dalvikvm(446):   | group="main" sCount=0 dsCount=0 obj=0x4001f1a8 self=0xce48
04-17 16:28:44.118: I/dalvikvm(446):   | sysTid=446 nice=0 sched=0/0 cgrp=default handle=-1345006528
04-17 16:28:44.118: I/dalvikvm(446):   | schedstat=( 276745040 468907344 84 )

Thanks for the help! 谢谢您的帮助!

JNI functions that accept objects require local or global refs. 接受对象的JNI函数需要本地或全局引用。 Pre-ICS these were raw pointers, but in ICS that changed to a table index system. 前ICS这些是原始指针,但在ICS中改为表索引系统。

You don't say what version was used to generate the output in the question. 您没有说明在问题中使用了什么版本来生成输出。 The hex value 0x4053dc70 looks like a raw pointer, so I'm assuming this is pre-ICS. 十六进制值0x4053dc70看起来像一个原始指针,所以我假设这是pre-ICS。 Looking at the error message, it appears that g_classBmrDeviceInfo is invalid; 查看错误消息,似乎g_classBmrDeviceInfo无效; a common way to get this wrong is to fail to use NewGlobalRef to convert a local reference to a global reference. 解决这个问题的常见方法是无法使用NewGlobalRef将本地引用转换为全局引用。

Generally speaking, JNI became more strict in ICS, so it's peculiar that this would succeed in 4.x but fail in 3.x, unless you're playing around with weak globals. 一般来说,JNI在ICS中变得更加严格,所以它在4.x中成功但在3.x中失败是特殊的,除非你正在玩弱全局变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android-不同的操作系统,不同的版本 - Android - different OS, different versions 针对不同的 Android 操作系统版本显示了不同的 xpath - Different xpaths are showing for different Android OS Versions 适用于不同Android OS版本的不同android设计风格 - Different android design style for different Android OS versions Android编程和不同版本之间的兼容性 - Android programming and compatability between different versions OS X和Android之间共享库中覆盖弱函数的不同行为 - Different behavior of override weak function in shared library between OS X and Android java.util.GregorianCalendar类在不同Android版本中的奇怪行为 - Strange behavior of the java.util.GregorianCalendar class in different android versions IBM Worklight-应用程序在不同的Android OS版本中显示并采取不同的操作 - IBM Worklight - Application displays and acts differently in different Android OS versions 不同手机/设备和操作系统版本上的Android堆大小 - Android heap size on different phones/devices and OS versions javax.crypto 在不同版本的 Android 操作系统中的工作方式不同? - javax.crypto working differently in different versions of Android OS? 不同Android版本上SurfaceView实施之间的区别 - Difference between SurfaceView implementation on different Android versions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM