安卓ICS 4.0 NDK NewStringUTF被轰然倒下的应用 [英] Android ICS 4.0 NDK NewStringUTF is crashing down the App

查看:817
本文介绍了安卓ICS 4.0 NDK NewStringUTF被轰然倒下的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JNI C / C ++这需要的jstring并返回的jstring一些事情一样,如下的方法,

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, jstring filename)
  {

// Get jstring into C string format.
  const char* cs = env->GetStringUTFChars (filename, NULL);
  char *file_path = new char [strlen (cs) + 1]; // +1 for null terminator
  sprintf (file_path, "%s", cs);
  env->ReleaseStringUTFChars (filename, cs);


  reason_code = INTERNAL_FAILURE;
  char* info = start_module(file_path);  


  jstring jinfo ;


  if(info==NULL)
  {
      jinfo = env->NewStringUTF(NULL);
  }
  else
  {
      jinfo = env->NewStringUTF(info);

  }


  delete info;

  info = NULL;
  return jinfo;
  }

在code可以完美地与现有的Andr​​oid 4.0版本,像2.2,2.3等。随着ICS 4.0检查JNI是在默认情况下,并由于它的应用程序崩溃引发了以下错误

The code works perfectly with prior android 4.0 versions like 2.2,2.3 and so on. With ICS 4.0 check JNI is on by default and because of it the app crashes throwing the following error

 08-25 22:16:35.480: W/dalvikvm(24027): **JNI WARNING: input is not valid Modified UTF-8: illegal  continuation byte 0x40**
08-25 22:16:35.480: W/dalvikvm(24027):              
08-25 22:16:35.480: W/dalvikvm(24027): ==========
08-25 22:16:35.480: W/dalvikvm(24027): /tmp/create
08-25 22:16:35.480: W/dalvikvm(24027): ==========
08-25 22:16:35.480: W/dalvikvm(24027): databytes,indoorgames,drop
08-25 22:16:35.480: W/dalvikvm(24027): ==========���c_ag����ϋ@�ډ@�����@'
 08-25 22:16:35.480: W/dalvikvm(24027):              in Lincom/inter       /ndk/comNDK;.rootNDK:(Ljava/lang/String;)Ljava/lang/String; **(NewStringUTF)**
08-25 22:16:35.480: I/dalvikvm(24027): "main" prio=5 tid=1 NATIVE
08-25 22:16:35.480: I/dalvikvm(24027):   | group="main" sCount=0 dsCount=0 obj=0x40a4b460   self=0x1be1850
08-25 22:16:35.480: I/dalvikvm(24027):   | sysTid=24027 nice=0 sched=0/0 cgrp=default handle=1074255080
08-25 22:16:35.490: I/dalvikvm(24027):   | schedstat=( 49658000 26700000 48 ) utm=1 stm=3 core=1
08-25 22:16:35.490: I/dalvikvm(24027):   at comrootNDK(Native Method)

我无能,我哪里错了。如果你看到上面的NewStringUTF是增加一些垃圾的价值为C的char *字节。

I am clueless as to where i am wrong. If you see above NewStringUTF is adding some garbage value to the c Char* bytes .

  1. 为什么这个任何想法正在发生的事情
  2. 在任何替代解决方案,以实现上述的欢迎

我真的AP preciate如果你可以帮我进去。在此先感谢

I really appreciate if one of you can help me in . Thanks in advance

regds 我

推荐答案

我通过返回字符串的字节数组,而不是解决了这个问题。在Java方面我现在转换字节数组字符串.Works罚款!远离使用NewStringUTF()为Android 4.0及以上版本,因为已经报道了谷歌Android NDK的错误。

I resolved this issue by returning byte array instead of String. On the Java side i am now converting the Byte array to Strings .Works fine! Stay away from using NewStringUTF() for Android 4.0 and above as there is already a bug reported on Google Android NDK.

这篇关于安卓ICS 4.0 NDK NewStringUTF被轰然倒下的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆