`
cppmule
  • 浏览: 436725 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

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.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics