Importing CMake-based Android Studio projects in VisualGDB

This tutorial shows how to import CMake-based Android Studio projects into VisualGDB using the new Advanced CMake Project Subsystem. VisualGDB will fully understand the structure of your CMakeLists.txt files and map the changes made in Visual Studio GUI back to them. It will also automatically configure the Clang IntelliSense based on the precise configuration reported by CMake.

Before you begin, install Android Studio 3.0 or later and VisualGDB 5.3R8 or later.

  1. Start Android Studio and begin creating a new project:01-newprj
  2. Select the location for your project and enable the “Include C++ Support” checkbox:02-type
  3. Select the SDK versions you want to target:03-phone
  4. Select to add a basic activity to the project:04-basic
  5. Proceed with the default activity name:05-act
  6. Finally press “Finish” to create the project:06-toolchain
  7. If you have just installed Android Studio, ensure to install CMake via File->Settings->Android SDK->SDK Tools->CMake:07-cmake
  8. Build the project and ensure it doesn’t report any errors:08-build
  9. Now we will show how to import the project into Visual Studio with VisualGDB. Start Visual Studio and open the VisualGDB Android Project Wizard:09-app
  10. If you are importing your first project, click “Configure SDK/NDK locations” and specify the locations of the Android tools. It is recommended to use the SDK/NDK versions installed by Android Studio to maximize compatibility:10-apps
  11. In the wizard select “Import Android Studio, Gradle/CMake or Eclipse Project”:11-import
  12. Specify the directory where the imported project is located:12-path
  13. Select the Android platform you would like to use:13-platforms
  14. Press “Finish” to create the project. VisualGDB will automatically recognize that the imported project is using CMake and will import it using the Advanced CMake Project Subsystem (the project icon in Solution Explorer should be the CMake icon):14-imported
  15. Advanced CMake projects integrate the Solution Explorer view with CMakeLists.txt files. E.g. right-click on libnative-lib.so and select “Go To Definition”:15-gotodefVisualGDB will open the CMakeLists.txt file defining the library.
  16. Try adding a new source file to the library:16-newitem
  17. Proceed with the default file location:17-another
  18. VisualGDB will automatically edit the CMakeLists.txt file for you reflecting the changes you made via Solution Explorer:18-added
  19. VisualGDB will also map VS Project Properties to CMakeLists.txt contents. E.g. set the “Additional Include Directories” value to automatically create or update the target_include_directories() statement:19-settings
  20. Ensure the startup debugging is enabled. Then connect your Android device, set a breakpoint in the function and press F5 to begin debugging:20-startup
  21. VisualGDB will stop at a breakpoint, letting you examine the program state:21-debug