Creating a command-line Android tool with VisualGDB

This tutorial explains how to develop and debug a command-line Android executable with Visual Studio.

Command-line Android tools are built using the “include $(BUILD_EXECUTABLE)” line and are supported by the Ultimate edition of VisualGDB 4.2 and later. Attaching to running tools is supported by VisualGDB 4.3+.

  1. Start Visual Studio. Begin creating a new project using VisualGDB Android Project wizard:01-toolprj
  2. Select “Create a command-line Android executable” in the wizard:02-exec
  3. Select the platform you are targeting on the second page of the wizard:03-platform
  4. Press Ctrl-Shift-B to build the tool:04-build
  5. Set a breakpoint on the printf() line, connect your Android device, install the drivers and press F5 to begin debugging. VisualGDB will deploy your tool on the device:05-deploy
  6. Once the tool is deployed and launched, your breakpoint will be triggered:06-breakpoint
  7. Press F5 to let the tool run to the end. Now we will show how to attach to the tool. Change the source code so that the tool asks for the user input before exiting and build your tool:07a-input
  8. Right-click on the project in Solution Explorer and select “VisualGDB Project Properties”. Go to the Debug Settings page:07-deploypath
  9. You can see that the tool is deployed to /data/local/tmp. You can change the deployment location and other options from here. Close the properties window and press Ctrl-F5 to deploy and start the tool without debugging. Due to the limitations of the Android ADB tool you won’t be able to send the text to your tool in this mode, so simply press Ctrl-C to end it:07b-instance
  10. Now we will launch our tool in the interactive mode. Select Android->Open Android Shell:08-shell
  11. Go to the deployment directory and launch the tool. Enter some text once the tool is running, but do not press Enter:09-launchtool
  12. Go back to VisualGDB Project Properties and select “Automatically attach to existing instance” on the Debug Settings page:10-attach
  13. Press F5 to begin debugging. VisualGDB will attach to your tool. Select Debug->Break All and examine the call stack. You will see that the tool is running the gets() function:11-stack
  14. Set a breakpoint on the last printf() call, resume execution and press Enter in the ADB console. The breakpoint will be triggered and you will see the line you entered:12-breakpoint

If you want to create an app containing native code instead, follow our Android App tutorial.