Debugging the hello-jni project with Visual Studio

Debugging the hello-jni project with Visual Studio

转载自:http://visualgdb.com/tutorials/android/hello-jni/

This quickstart guide shows how to build and debug the hello-jni simple sample from Android NDK.

Before you begin, please install VisualGDB 2.0 (ensure that "Android Edition" is checked in the installer).

  1. Start Visual Studio. Select File->New project->Visual C++->VisualGDB->Android App Wizard.
  2. We will make a copy of the hello-jni sample project to experiment with it leaving the original files untouched. Please select a directory and a name for the project copy.
  3. If you are running VisualGDB Android wizard for the first time, please press the "Configure NDK/SDK locations" button to tell VisualGDB the locations of your Android-related tools. If you don't have any of the tools installed, simply press the "install" button.WARNING! After installing Android SDK please run the SDK manager as Administrator and install the Tools (SDK tools/Platform tools) and all required Android APIs (at least Android 1.5 and  2.3.3).
  4. In this tutorial we are creating a copy of an existing NDK sample. Please select the second option to do this:
  5. The next page allows selecting a sample project to copy. Please select hello-jni and press "next".
  6. Finally VisualGDB wizard will ask you for the targeted Android platform. You will be able to change the platform in the VisualGDB project settings later. Please select Android 1.5 for now.
  7. When you press "Finish", VisualGDB will create a copy of the hello-jni sample for you. If you have an Android phone or a tablet, you can enable USB debugging on it and connect it to your PC. If not, please start the Android simulator (AVD Manager) by selecting "Android->AVD Manager" in Visual Studio:
  8. If you have no virtual devices defined by now, please create one. It is recommended to specify at least Android 2.3.3 as the simulator platform.
  9. Start the virtual device. While it is booting, go to Visual Studio, and select Build->Build Solution.
  10. Once the solution has been built, please ensure that the virtual Android device has been started.
  11. Once the device is ready, go to Visual Studio and select Debug->Start Debugging with GDB. VisualGDB will deploy the APK file automatically and will start a debugging session.
  12. If you are using the simulator instead of a real Android device, it might take up to several minutes for the debugging to start.
  13. Once the debugging is started, you can use the Visual Studio interface to set breakpoints, stop program execution, step through code or inspect variables. You will additionally see the output from the gdbserver in the Remote Console window:
  14. Go to the simulator and ensure that the app has been started.
  15. As the native function is only invoked during startup when the debugger is not yet attached, setting a breakpoint there won't result in any hits. You can either modify the Java code to call the native function continuously, or use the Debug->Break All command:
  16. You can use the Threads and Call Stack windows to observe currently running threads and their stacks:
  17. When you are done debugging, press Shift+F5 to close the app.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值