Skip to content

Instantly share code, notes, and snippets.

@charafau
Created April 12, 2021 00:40
Show Gist options
  • Save charafau/a496a557b6b7686f491bc5ea75fc2981 to your computer and use it in GitHub Desktop.
Save charafau/a496a557b6b7686f491bc5ea75fc2981 to your computer and use it in GitHub Desktop.
Flutter plugin vscode linux development with debugging
  1. Create example plugin project flutter create --org com.example --platforms=linux myapp
  2. From myapp/example run flutter run and quit the app
  3. Install vscode
  4. Install flutter plugin
  5. Install MS C++ plugin https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
  6. Switch to Insider channel for new features
  7. When opening project VS code should ask you if you want to configure CMake project - answerr YES and click Locate cmake file now this is important choose - myapp/example/linux/CMakeLists.txt NOT the one from myapp/linux
  8. You will probably have to relaunch vscode
  9. inside myapp/ folder create .vscode (notice the dot) folder
  10. create c_cpp_properties.json :
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}
  1. Create settings.json
{
    "cmake.sourceDirectory": "${workspaceFolder}/example/linux",
    "cmake.configureOnOpen": true,
    "files.associations": {
        "cstring": "cpp"
    }
}
  1. Finally create launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Flutter",
            "cwd": "example",
            "request": "launch",
            "type": "dart",
            "args": [
                "--local-engine",
                "/home/charafau/Utils/engine/src/out/host_debug_unopt"
            ]
        },
        {
            "name": "Debug native",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/example/build/linux/x64/debug/bundle/myapp_example",
            "cwd": "${workspaceFolder}"
        }
    ]
}

take a look at this line: "program": "${workspaceFolder}/example/build/linux/x64/debug/bundle/myapp_example",

This points to binary and will change to the name of your project, so check this folder and correct your path

also you will have remove those lines or correct paths:

 "args": [
                "--local-engine",
                "/home/charafau/Utils/engine/src/out/host_debug_unopt"
          ]

I run custom build engine to you might not need that

You will have now two configurations in vscode - one for running example project and one for debugging native binary (it also launches the project)

!!! Notice that everytime you change something in your project you need to run flutter run in order to recompile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment