Debugging the native-audio 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 File->New project->VisualGDB->Android Project Wizard.01-newprj
  2. Specify the path for the new project and an arbitrary project name (e.g. NativeAudioTest) and press OK.
  3. In VisualGDB wizard select Clone a Sample from NDK.02-clone
  4. On the next page select native-audio from the sample list.03-native-audio
  5. On the last wizard page select a platform that supports Native Audio API (e.g. Android 2.3.3).04-platform
  6. Press Finish to create the project. Build it by selecting Build->Build Solution.05-assert
  7. If you see build errors related to bqRecorderBufferQueue variable, double-click at the error message in Error list so that Visual Studio will navigate to the problem. Then comment out the line causing it. Build the solution again.06-builddone
  8. If you want to use a physical device, prepare it for debugging and connect it. If you want to use Android Emulator, select Android->AVD Manager in Visual Studio. When the AVD Manager opens, create a virtual device based on Android 2.3.3 or later and start it. Wait till the device starts up completely.07-avd
  9. To test debugging functionality, we’ll set  a
    breakpoint inside the function selecting a buffer to play
    with native audio API (Java_com_example_nativeaudio_NativeAudio_selectClip() ). Please put the breakpoint after the line with the CLIP_HELLO comment. Then select Android->Debug Android App.08-bkpt
  10. If you are using the emulator, installing the APK file and loading it might take some time. Wait until the “Debug Initializing” window disappears.09-start
  11. Go to Android emulator and press the “Hello” button in the app.10-hello
  12. The breakpoint will trigger. Normally, this should result in playing the “hello” sample. However, we’ll test the debugger by forcing it to play the sawtooth sample instead. Right-click at the line with the CLIP_SAWTOOTH comment and select Set Next Statement.11-setnext
  13. Notice that your the line selecting sawtoothBuffer became active.12-jump
  14. Press F5 to continue running the program. The emulator will play the sawtooth sample.
  15. To finish debugging, press Shift+F5.