I am developing a package in C++ to be used in a Flutter app (and therefore in Dart), using dart::ffi and I was wondering if there was a better way to debug (step by step, variable watch, that sort of things) the C++ code, other than logging messages. I've tried both in Android Studio and VS Code, with no success.
-
Visual Studio 2019 – Michael Chourdakis Jun 12 '20 at 19:38
-
How would you suggest I do it? As far as I know, I can't run the Flutter app in Visual Studio 2019 – Facundo Farall Jun 12 '20 at 19:44
-
Why can't you run it? – Michael Chourdakis Jun 12 '20 at 19:50
-
According to [this](https://flutter.dev/docs/get-started/editor?tab=vscode), the IDEs that you can use to debug are Android Studio, IntelliJ, VS Code and Emacs. Have you tried running a Flutter app in Visual Studio? – Facundo Farall Jun 12 '20 at 19:59
2 Answers
Android Studio (or VS Code) doesn't support native (C/C++) code debugging while in Flutter mode (yet). However, there is a workaround! In the project tree, right-click the 'android' folder and select Flutter -> Open Android module in Android Studio. The project will switch to Android development mode where c/c++ debugging is fully supported. Now just search for the 'cpp' folder, set breakpoints in any of the files there and run the app (while still in the Android development mode of course)!

- 116
- 2
I managed to debug some c code in VS Code using the follow configuration in launch.json, for a linux desktop app:
{
"name": "Debug Native",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/linux/x64/debug/bundle/app",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/linux/x64/debug/bundle",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
Just modify the app
in program according to the name of your app. Then in the debug tab you will be able to launch this configuration:
This configuration just launches the built executable. If you want it to build everytime before launching you need to add a preLaunchTask
.

- 6,463
- 2
- 20
- 23