Debugging the native-activity project with Visual Studio

This tutorial shows how to build and debug the Native-activity sample provided with Android NDK.

Before you begin, please install VisualGDB 2.0 or later (ensure that “Android Edition” is checked in the installer). If you are not familiar with VisualGDB, please first go through the Android Quickstart tutorial.

  1. Start Visual Studio. Select Android->AVD Manager to start Android Emulator.01-avd
  2. If you already have a virtual Android device based on version 2.3.3 or later, start it. Otherwise, create a new virtual device (versions before 2.3.3 do not support native activities!).
  3. Go back to Visual Studio. Select File->New project->VisualGDB->Android Project Wizard.02-newprj
  4. Enter a path for the new project and specify an arbitrary project name. Press “OK”.
  5. Select “Clone a sample from NDK” and press “Next”.03-clone
  6. Select “native-activity” from the sample list. Press “next”.04-native-activity
  7. Select “Android 2.3.3” from the platform list. Press “next”.05-platform
  8. Build your project by selecting “Build->Build Solution”.
  9. Open the main.c file and set a breakpoint after the “Process the event” comment.
  10. Start debugging by selecting Android -> Debug Android App.06-debug
  11. Wait until VisualGDB deploys the app, launches it and attaches to it.07-launch
  12. After VisualGDB attaches to the app, the breakpoint should hit. If this does not happen, go to the emulator and click on the screen. Then go back to Visual Studio.08-inspect
  13. You can now use the usual Visual Studio windows (e.g. call stack or watch) and commands (e.g. step over) to debug your program.
  14. To finish debugging, press Shift+F5.