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.
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)!
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
.
© 2022 - 2024 — McMap. All rights reserved.