Dart-code: Can't launch Flutter app from a multi-root workspace with a launch configuration

Created on 11 Jul 2018  ·  12Comments  ·  Source: Dart-Code/Dart-Code

Environment

Flutter: 0.5.1 Beta Channel
MacOS: 10.13.5
Visual Studio Code: 1.25
Dart Code: 2.15

Steps to Repro

1) Create a new plugin project:

flutter create -t plugin myplugin

2) Create a multi-root workspace file in the new project

{
    "folders": [
        {
            "path": "example",
            "name": "Example"
        },
        {
            "path": ".",
            "name": "Root"
        }
    ],
    "settings": {},
    "launch": {
        "configurations": [
            {
                "name": "Example Debug",
                "program": "/${workspaceFolder:Example}/lib/main.dart",
                "request": "launch",
                "type": "dart",
                "flutterMode": "debug"
            }
        ],
        "compounds": []
    }
}

3) Save As… the file as myplugin.code-workspace in the myplugin directory.

4) Open the myplugin workspace in VS Code using Open Workspace…

5) Press F5 to Start Debugging…

Actual Results:

The Debug controls window appears, the Status bar turns orange, and the Debug Console is displayed. Wait as long you like but no messages appear in the Debug Console and the app will never launch.

Expected Results:

The app launches into debug mode.

Logs:

There was no significant log output while the app was attempting to launch.

Dart Code extension: 2.15.0
Flutter extension: 2.15.0
Platform: mac
Workspace type: Flutter
Multi-root?: true
Dart SDK:
    Loc: /Users/tony/afero/flutter/bin/cache/dart-sdk
    Ver: 2.0.0-edge.c080951d45e79cd25df98036c4be835b284a269c
Flutter SDK:
    Loc: /Users/tony/afero/flutter
    Ver: 0.5.1

Wed Jul 11 2018 [12:44:11 GMT-0700 (PDT)] Log file started
Wed Jul 11 2018 [12:53:33 GMT-0700 (PDT)] Log file ended

Flutter Doctor

[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-US)
    • Flutter version 0.5.1 at /Users/tony/afero/flutter
    • Framework revision c7ea3ca377 (6 weeks ago), 2018-05-29 21:07:33 +0200
    • Engine revision 1ed25ca7b7
    • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/tony/Library/Android/sdk
    • Android NDK at /Users/tony/Library/Android/sdk/ndk-bundle
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] VS Code (version 1.25.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.14.0

[✓] Connected devices (2 available)
    • Ranger   • [REDACTED] • ios • iOS 11.4.1
    • iPhone X • 93ED801E-E0FB-4B97-8F7D-AB12185BEA9E     • ios • iOS 11.4 (simulator)

• No issues found!

Not sure why Flutter Doctor is reporting VS Code Flutter Extension v2.14. VS Code report v2.15. Here's a screenshot of my installed extensions:
image

Most helpful comment

This worked for me.
{
"name": "App-Name-Flutter",
"request": "launch",
"type": "dart",
"program": "${workspaceFolder}/packages/name-app/lib/main.dart"
}

All 12 comments

I'm going to make a new beta build soon (hopefully today) I'd like you to try - it has two things:

  1. Additional logging in debug launching
  2. Better support for running projects from sub-folders (eg. example) without needing a launch config

That said, I think the / in front of your program value is bogus. It's possible that's causing the issue, though I couldn't repro - it all launched fine for me (though I did notice something else that could be an issue - which I've opened https://github.com/Microsoft/vscode/issues/54136 for).

Try without the slash, and I'll ping you here when there's a beta of v2.16 available you may wish to try.

Removing the slash produces the same results as described. I had added the slash previously because without it, v2.14 would produce an error unable to find main.dart. Adding the slash fixed this problem and allowed v2.14 to build successfully. v2.15 just blocks in both cases.

Here's something interesting. I changed the path to:

     "program": "./example/lib/main.dart",

Pressed F5, and I get this error dialog:
image

If you put the launch config inside the example folder and just use ${workspaceFolder} I suspect it'll work. I'm not sure if we can fix this properly without VS Code implementing the feature I linked.

I'm still hoping to make a v2.16 beta before the day is out though, so if you upgrade to that I think you'll be able to just remove your launch configs if you want (when you press F5 it'll figure out what to run based on the active file; so if it's inside the examples folder it'll run the example project). I don't know that it's perfect, but should cover most cases.

Yes, we can indeed work-around the hanging bug by removing the launch configs. What I was originally trying to achieve by adding the launch config to the workspace was the ability to launch the app regardless of the active file. I have a more complex project where this problem originally cropped up. It has an app sub-dir and multiple sibling directories (components, sdk, etc.) that contain app dependencies. It's really annoying to be working in a non-app component and not be able to quickly launch the app without having to bring one of the app files to the front. The launch configs in the workspace seemed to be designed exactly for this situation, but it doesn't seem to work as expected.

I understand; though unfortunately I can't properly fix this without help from VS Code (it doesn't give me any way to resolve ${workspaceFolder:Example} to its real path. Please 👍 on https://github.com/Microsoft/vscode/issues/54136.

That said, I can't reproduce the hang so it's possible we can get past that. Here's a beta of v2.16

https://github.com/Dart-Code/Dart-Code/releases/tag/v2.16.0-beta.2

There are things in it that might help:

  1. There are changes to the debug adapter launching that might affect how things work a little
  2. The full debug adapter launch process is now logged, so if you run Capture Logs and then try to launch, we should get a full log of exactly what's happening and what it's trying to do.

Thanks Dan! I'll give v2.16 a shot and let you know how it goes.

Ok, the hang is gone with v2.16b2, and it behaves pretty much like v2.14 from my perspective - a file from the app's directory must be active to launch. So, I can at least leave my launch config in the workspace file and hopefully that will start working better once vscode#54136 is fixed and you can take advantage of it.

a file from the app's directory must be active to launch

Can you expand on this - if using a launch config, there shouldn't be any requirements around the open file?

You are correct, with a launch config the open file doesn't matter anymore. Seemed like it did matter in earlier versions, but I was focused on using the workspace so I'm not sure.

Ok, thanks for confirming! I'll close this since I don't think there's anything to do, but if you do notice anything wonky where it's not doing what you expect or you think can be improved, please do post back!

This worked for me.
{
"name": "App-Name-Flutter",
"request": "launch",
"type": "dart",
"program": "${workspaceFolder}/packages/name-app/lib/main.dart"
}

Was this page helpful?
0 / 5 - 0 ratings