How to transfer the Android Studio debug configuration to VS Code debug for Flutter

75 views Asked by At

I need to transfer this configuration to the visual file 'launch.json,' but it's not working when I edit the parameters, and the startup parameters are not specifically listed either.

Android Studio | Debug config

VS Code | Debug config

I already tried adding the 'args' in VS Code, but I still couldn't connect in the same way

2

There are 2 answers

0
Tommy Elliott On
  1. You'll want to make sure you first install the Flutter and Dart extensions for VS Code.
  2. You can add configurations in a guided way in VS Code by opening the .vscode/launch.json file in VS Code, and tapping the "Add Configuration..." button that appears on the bottom right of the editor area with the file contents. You can also get to that (and/or generate one if none exists yet) by going to the Run tab on the left sidebar, and selecting "Add Configuration..." from the dropdown menu there.
  3. For run configurations using parameters such as your Android Studio config file shows, you can use a format like this:
{
    // 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": "myapp (DEV-debug)",
            "request": "launch",
            "type": "dart",
            "flutterMode": "debug",
            "toolArgs": [
                "--web-port",
                "1234",
                "--dart-define",
                "MYAPP_ENVIRONMENT=DEV",
            ],
        },
        //Release and Profile modes are only available on actual devices
        //(not on emulator/simulator),
        //and Profile mode is for measuring performance
        //(otherwise it is like Release mode).
        //You can build for those modes with the `"flutterMode": "profile"`
        //or`"flutterMode": "release"` value, but they will not
        //be debuggable and will only run on actual devices.
        //See https://docs.flutter.dev/testing/build-modes
        {
            "name": "myapp (TEST-release)",
            "request": "launch",
            "type": "dart",
            "flutterMode": "release",
            "toolArgs": [
                "--web-port",
                "1234",
                "--dart-define",
                "MYAPP_ENVIRONMENT=TEST",
            ],
        },
        {
            "name": "myapp (PROD-release)",
            "request": "launch",
            "type": "dart",
            "flutterMode": "release",
            "toolArgs": [
                "--web-port",
                "1234",
                "--dart-define",
                "MYAPP_ENVIRONMENT=PROD",
            ],
        },
        {
            "name": "myapp (PROD-profile)",
            "request": "launch",
            "type": "dart",
            "flutterMode": "profile",
            "toolArgs": [
                "--web-port",
                "1234",
                "--dart-define",
                "MYAPP_ENVIRONMENT=PROD",
            ],
        },
    ],
}

If you need to use multiple dart-defines, just repeat the corresponding two lines for defining each of them, like an additional "--dart-define", and "MYAPP_SHOW_ADMIN_MODE_SWITCH=true",.

0
F Perroch On

You can add the args property to add your arguments on your configuration like this

{
  "name": "app",
  "request": "launch",
  "type": "dart",
  "args": ["--web-port", "8000", "--dart-define", "ENVIRONMENT=DEV"]
},