Using Visual Studio to Develop Native Android Code

This tutorial shows how to build and debug a simple Android App with a native library with Visual Studio.

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

You will also need to install Java JDK, Android SDK, NDK and Apache ANT.

Step-by-step tutorial

  1. Start Visual Studio. Select File->New project->VisualGDB->Android App Wizard.
  2. Specify your project name and location (please avoid spaces in file path). Press OK to start the wizard.
  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'll go the easiest way and simply create a new application from scratch. To do it, please select the first option in the wizard:
  5. On the next page you can customize the project name or leave the default names.
  6. Finally you can select the Android platform. If you see not platforms in the list, please press the "Manage installed platforms" button and install the required platforms. Please select "Android 1.5" as the app platform.
  7. When you press "Finish", VisualGDB will create a new Android App project 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, set a breakpoint on the sprintf() line inside the main C file and 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, press F5 to start debugging. VisualGDB will deploy the APK file automatically and will start a debugging session.
  12. Please go to the simulator and click on the huge full-screen button.
  13. Clicking the button will trigger the sprintf() breakpoint in Visual Studio:
  14. Hover the mouse over s_ButtonPressCounter, click on "0", change the value to "123" and press ENTER.
  15. Press F5 to continue running the app. Go back to the simulator and ensure that the label indicates 123 hits.
  16. Have a look through the main debugging windows provided by VisualGDB using the Debug->Windows command:
    • The GDB Session window allows sending arbitrary commands to the GDB debugger
    • The Android LogCat window shows additional logging information provided by Android
    • The GDBServer Console window shows various NDK debugging information.
  17. Press Shift+F5 to stop debugging.
  18. As VisualGDB uses the Android NDK build system in the background, you can modify various build flags and settings by editing the Android.mk file. Note that VisualGDB will automatically update the LOCAL_SRC_FILES for you when you add/remove source files in the solution: