Windows 7 OS,如何Debug NDK Hello-JNI Sample程序

本文详细介绍了如何在Eclipse中安装Android NDK插件、配置环境变量、导入示例项目并进行初步调试。通过解决Eclipse中出现的编译错误,最终实现了HelloJNI项目的成功运行。

  1. 首先,需要明确的是不需要CygWin

  2. ADT中安装NDK插件

    Help | Install New Software …菜单,然后从http://dl-ssl.google.com/android/eclipse/安装AndroidNative Development Tools

     

  3. 然后,Window | Preferences 菜单,确认Android下面有一个NDK选项

  4. C/C++ | Build | Environment下增加一个”NDK_DEBUG”环境变量,并将其值设为1

  5. Eclipse中,Import进来Hello JNI Sample

  6. 然后,右键单击Hello JNI ProjectAndroid Tools > AddNative Support,然后,接受缺省地Hello-JNI Library

     

  7. Eclipse会报“Method NewStringUTF()could not be resolved”错误。请参考http://stackoverflow.com/questions/15899813/eclipse-method-newstringutf-could-not-be-resolved以消除它。

     

    Go to the project's Properties -> C/C++ General -> Code Analysis.Click the "Use project settings" radio button (or "ConfigureWorkspace Settings..." button). Disable (uncheck) the "Method cannotbe resolved" checkbox. Click "Apply," "OK." Then foryour project, refresh, clean, refresh, build.

  8. Eclipse中,右键单击Hello JNI ProjectRun | Debug as AndroidApplication。确认程序能运行成功。然后,在模拟器或真机上退出Hello JNI App

  9. 启动一个命令行窗口,进入到Hello JNI目录。然后,运行“ndk-gdb --start--verbose”命令。

  10. 然后, gdb中设置断点,并运行其它调试命令

     (gdb) b hello-jni.c:62

    No symbol table is loaded.  Use the "file" command.

    Breakpoint 1 (hello-jni.c:62)pending.

    (gdb) c

    Continuing.

    Exception in thread Thread-3:

    Traceback (most recent calllast):

     File "C:\Python34\lib\threading.py", line 920, in_bootstrap_inner

        self.run()

     File "C:\Python34\lib\threading.py", line 868, in run

        self._target(*self._args, **self._kwargs)

     File"C:\Users\Qingxu_Li\AppData\Local\Android\android-ndk-r10d\ndk-gdb.py",l

    ine 353, in async_stderr

        output_fn(line.replace('\r','').replace('\n', ''))

    TypeError: expected bytes,bytearray or buffer compatible object

     

     

    Breakpoint 1,Java_com_example_hellojni_HelloJni_stringFromJNI (

        env=0x41c77e00, thiz=0xd2e00019) atjni/hello-jni.c:62

    62          return (*env)->NewStringUTF(env,"Hello from JNI !  Compiled with AB

    I " ABI ".");

    (gdb) bt

    #0 Java_com_example_hellojni_HelloJni_stringFromJNI (env=0x41c77e00,

        thiz=0xd2e00019) at jni/hello-jni.c:62

    #1  0x40b81550 in ?? ()

    #2  0x40b81550 in ?? ()

    Backtrace stopped: previousframe identical to this frame (corrupt stack?)

    (gdb) frame

    #0 Java_com_example_hellojni_HelloJni_stringFromJNI (env=0x41c77e00,

        thiz=0xd2e00019) at jni/hello-jni.c:62

    62          return (*env)->NewStringUTF(env,"Hello from JNI !  Compiled with AB

    I " ABI ".");

    (gdb)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值