Repository navigation
Flutter SDK installed via package managers like Hermit are not detected/initialized correctly #3961
Description
Describe the bug
The VSCode extensions are unable to find Flutter or Dart (see attached log below) if ./bin/dart or ./bin/flutter exist, even though FLUTTER_ROOT is set correctly. I would expect that with FLUTTER_ROOT explicitly set, it would be used by the extension. The flutter/dart command-line tools work perfectly FWIW.
Flutter is installed in /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0.
FLUTTER_ROOT is set export FLUTTER_ROOT=/Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
I have a shell script wrapper around dart/flutter located in ~/Projects/flutter/bin (basically #!/bin/bash\nexec /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/$cmd). On the command line this works perfectly (screenshot below), but the VSCode extension preferences the wrapper scripts over FLUTTER_ROOT, resulting in it being unable to find Dart or the Flutter SDK.
I understand that this is not a common setup, but we use a tool called Hermit for managing hermetic environments which uses wrapper scripts to bootstrap tools, including Flutter.
To Reproduce
Install Flutter SDK into some location. Set FLUTTER_ROOT to that location then:
mkdir -p ~/test/bin
cd ~/test
echo 'exec $FLUTTER_ROOT/bin/flutter "$@"' > bin/flutter
echo 'exec $FLUTTER_ROOT/bin/dart "$@"' > bin/dart
chmod +x bin/{flutter,dart}
export PATH="$PWD/bin:$PATH"
flutter doctor
flutter create .
flutter run
The above all works.
Next do the following:
code .
This results in the extension reinitialising and failing with:

Expected behavior
I would expect that with FLUTTER_ROOT explicitly set, it would be used by the extension.
Screenshots
Extension log section
[3:16:59 pm] [General] [Info] Searching for flutter
[3:16:59 pm] [General] [Info] Looking for flutter in:
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/.flutter
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/.flutter/bin
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/vendor/flutter
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/vendor/flutter/bin
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info] /Users/aat/flutter-sdk
[3:16:59 pm] [General] [Info] /Users/aat/flutter-sdk/bin
[3:16:59 pm] [General] [Info] /google/flutter
[3:16:59 pm] [General] [Info] /google/flutter/bin
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info] /Users/aat/bin
[3:16:59 pm] [General] [Info] /opt/homebrew/bin
[3:16:59 pm] [General] [Info] /opt/homebrew/bin
[3:16:59 pm] [General] [Info] /opt/homebrew/sbin
[3:16:59 pm] [General] [Info] /usr/local/bin
[3:16:59 pm] [General] [Info] /usr/bin
[3:16:59 pm] [General] [Info] /bin
[3:16:59 pm] [General] [Info] /usr/sbin
[3:16:59 pm] [General] [Info] /sbin
[3:16:59 pm] [General] [Info] /opt/local/bin
[3:16:59 pm] [General] [Info] /usr/local/munki
[3:16:59 pm] [General] [Info] /usr/local/munki/bin
[3:16:59 pm] [General] [Info] /Applications/kitty.app/Contents/MacOS
[3:16:59 pm] [General] [Info] /Applications/kitty.app/Contents/MacOS/bin
[3:16:59 pm] [General] [Info] /opt/homebrew/opt/fzf/bin
[3:16:59 pm] [General] [Info] Found at:
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter/bin
[3:16:59 pm] [General] [Info] Following symlink: /Users/aat/Projects/flutter/bin/flutter ==> /Users/aat/Projects/flutter/bin/hermit
[3:16:59 pm] [General] [Info] Following symlink: /Users/aat/Projects/flutter/bin/flutter ==> /Users/aat/Projects/flutter/bin/hermit
[3:16:59 pm] [General] [Info] Candidate paths to be post-filtered:
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:16:59 pm] [General] [Info] /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info] Found at /Users/aat/Projects/flutter
[3:16:59 pm] [General] [Info] Returning SDK path /Users/aat/Projects/flutter for flutter
[3:16:59 pm] [General] [Info] Flutter is not initialized, running 'flutter doctor' to force...
[3:16:59 pm] [General] [Info] (PROC 23519) Logging data for process...
[3:16:59 pm] [FlutterDaemon] [Info] Process /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin/flutter terminated! 0, null
[3:17:01 pm] [General] [Info] (PROC 23519) [✓] Flutter (Channel stable, 3.0.0, on macOS 12.3.1 21E258 darwin-arm (Rosetta), locale en-AU)
[3:17:01 pm] [General] [Info] (PROC 23519) • Flutter version 3.0.0 at /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:17:01 pm] [General] [Info] (PROC 23519) • Upstream repository https://github.com/flutter/flutter.git
[3:17:01 pm] [General] [Info] (PROC 23519) • Framework revision ee4e09cce0 (4 days ago), 2022-05-09 16:45:18 -0700
[3:17:01 pm] [General] [Info] (PROC 23519) • Engine revision d1b9a6938a
[3:17:01 pm] [General] [Info] (PROC 23519) • Dart version 2.17.0
[3:17:01 pm] [General] [Info] (PROC 23519) • DevTools version 2.12.2
[3:17:01 pm] [General] [Info] (PROC 23519)
[3:17:01 pm] [General] [Info] (PROC 23519) [✗] Android toolchain - develop for Android devices
[3:17:01 pm] [General] [Info] (PROC 23519) ✗ Unable to locate Android SDK.
[3:17:01 pm] [General] [Info] (PROC 23519) Install Android Studio from: https://developer.android.com/studio/index.html
[3:17:01 pm] [General] [Info] (PROC 23519) On first launch it will assist you in installing the Android SDK components.
[3:17:01 pm] [General] [Info] (PROC 23519) (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
[3:17:01 pm] [General] [Info] (PROC 23519) If the Android SDK has been installed to a custom location, please use
[3:17:01 pm] [General] [Info] (PROC 23519) `flutter config --android-sdk` to update to that location.
[3:17:01 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[3:17:02 pm] [General] [Info] (PROC 23519) • Xcode at /Applications/Xcode.app/Contents/Developer
[3:17:02 pm] [General] [Info] (PROC 23519) • CocoaPods version 1.11.3
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] Chrome - develop for the web
[3:17:02 pm] [General] [Info] (PROC 23519) • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [!] Android Studio (not installed)
[3:17:02 pm] [General] [Info] (PROC 23519) • Android Studio not found; download from https://developer.android.com/studio/index.html
[3:17:02 pm] [General] [Info] (PROC 23519) (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] IntelliJ IDEA Community Edition (version 2022.1)
[3:17:02 pm] [General] [Info] (PROC 23519) • IntelliJ at /Users/aat/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5080.210/IntelliJ IDEA CE.app
[3:17:02 pm] [General] [Info] (PROC 23519) • Flutter plugin can be installed from:
[3:17:02 pm] [General] [Info] (PROC 23519) 🔨 https://plugins.jetbrains.com/plugin/9212-flutter
[3:17:02 pm] [General] [Info] (PROC 23519) • Dart plugin can be installed from:
[3:17:02 pm] [General] [Info] (PROC 23519) 🔨 https://plugins.jetbrains.com/plugin/6351-dart
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:02 pm] [General] [Info] (PROC 23519) [✓] VS Code (version 1.67.1)
[3:17:02 pm] [General] [Info] (PROC 23519) • VS Code at /Applications/Visual Studio Code.app/Contents
[3:17:02 pm] [General] [Info] (PROC 23519) • Flutter extension version 3.40.0
[3:17:02 pm] [General] [Info] (PROC 23519)
[3:17:04 pm] [General] [Info] (PROC 23519) [✓] Connected device (2 available)
[3:17:04 pm] [General] [Info] (PROC 23519) • macOS (desktop) • macos • darwin-arm64 • macOS 12.3.1 21E258 darwin-arm (Rosetta)
• Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.64
[3:17:04 pm] [General] [Info] (PROC 23519) [✓] HTTP Host Availability
[3:17:04 pm] [General] [Info] (PROC 23519) • All required HTTP hosts are available
[3:17:04 pm] [General] [Info] (PROC 23519) ! Doctor found issues in 2 categories.
[3:17:04 pm] [General] [Info] (PROC 23519) exited (0, null)
[3:17:04 pm] [General] [Info] (PROC 23519) closed (0, null)
[3:17:04 pm] [General] [Info] Flutter initialized!
[3:17:04 pm] [General] [Info] Searching for dart
[3:17:04 pm] [General] [Info] Looking for dart in:
[3:17:04 pm] [General] [Info] /Users/aat/Projects/flutter/bin/cache/dart-sdk
[3:17:04 pm] [General] [Info] /Users/aat/Projects/flutter/bin/cache/dart-sdk/bin
[3:17:04 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:17:04 pm] [General] [Info] /Users/aat/Projects/flutter/bin
[3:17:04 pm] [General] [Info] /Users/aat/bin
[3:17:04 pm] [General] [Info] /opt/homebrew/bin
[3:17:04 pm] [General] [Info] /opt/homebrew/bin
[3:17:04 pm] [General] [Info] /opt/homebrew/sbin
[3:17:04 pm] [General] [Info] /usr/local/bin
[3:17:04 pm] [General] [Info] /usr/bin
[3:17:04 pm] [General] [Info] /bin
[3:17:04 pm] [General] [Info] /usr/sbin
[3:17:04 pm] [General] [Info] /sbin
[3:17:04 pm] [General] [Info] /opt/local/bin
[3:17:04 pm] [General] [Info] /usr/local/munki
[3:17:04 pm] [General] [Info] /usr/local/munki/bin
[3:17:04 pm] [General] [Info] /Applications/kitty.app/Contents/MacOS
[3:17:04 pm] [General] [Info] /Applications/kitty.app/Contents/MacOS/bin
[3:17:04 pm] [General] [Info] /opt/homebrew/opt/fzf/bin
[3:17:04 pm] [General] [Info] /Users/aat/Projects/flutter/bin/cache/dart-sdk
[3:17:04 pm] [General] [Info] /Users/aat/Projects/flutter/bin/cache/dart-sdk/bin
[3:17:04 pm] [General] [Info] Found at:
[3:17:04 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0/bin
[3:17:04 pm] [General] [Info] /Users/aat/Projects/flutter/bin
[3:17:04 pm] [General] [Info] Following symlink: /Users/aat/Projects/flutter/bin/dart ==> /Users/aat/Projects/flutter/bin/hermit
[3:17:04 pm] [General] [Info] Candidate paths to be post-filtered:
[3:17:04 pm] [General] [Info] /Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0
[3:17:04 pm] [General] [Info] /Users/aat/Projects/flutter
[3:17:04 pm] [General] [Info] Returning SDK path undefined for dart
[3:17:04 pm] [General] [Info] Done!
Please complete the following information:
- Operating System and version: 12.3.1 (21E258)
- VS Code version: 1.67.1 (Universal)
- Dart extension version: v3.40.0
- Dart/Flutter SDK version: 3.0.0

Activity
alecthomas commentedon May 14, 2022
Ah I do see that the search order seems to be deliberate, which seems a bit odd to me, but either way I think that if
flutteranddartwork, then the VSCode extension should work too. But maybe it has no way of finding the real SDK location?DanTup commentedon May 14, 2022
VS Code needs to locate a real SDK because it needs the path for some of its functionality (for example when debugging, we need to be able to translate
dart:xxxURIs into paths to the source files inside your SDK folder). If your shell scripts were instead symlinks to the real SDK binaries, I would expect the SDK is found (because we resolve symlinks during the search).Some questions:
flutterand then using the real SDK binary directly work?alecthomas commentedon May 14, 2022
Ah okay, that makes complete sense.
$CACHEDIR/hermit/pkg/flutter-3.0.0.Interestingly the VSCode extension log does know about Hermit's installed Flutter location.
FTR this is Hermit's flutter package. It doesn't currently work out of the box because flutter requires its installation location to be mutable, which is slightly unfortunate, but I've been doing this manually, and I'm also thinking of adding a
mutable = trueoption to Hermit to support this.Within the aforementioned constraints of Hermit, I'd be interested in figuring out a way to make VSCode work with it. Let me know if there's anything I can do to help.
DanTup commentedon May 14, 2022
I'm not familiar with either. Is it Hermit that is creating
~/Projects/flutter/bin? (Or more specifically, if other users are using Hermit, would their wrapped script be at this exact location too, or is this a custom script you have created?)Which of these paths do you have on
PATH? Would it be reasonable/valid to have both of these (in this order) onPATH?~/Projects/flutter/bin/Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0This setup doesn't sound completely different from Snap on Ubuntu. After installing the snap package there is a
flutterbinary that is not part of a valid SDK. If we fail to find an SDK but we do find that binary, we invoke the binary (and wait for it to complete, which can be slow if it's downloading Flutter) and then re-search for the SDK (and find the real SDK).I wonder if we could add some setting (or env var) that would allow you to configure a path to a "flutter initialisation script" that we could invoke if no SDK is found as part of initialisation.
alecthomas commentedon May 14, 2022
The
bindirectory is created byhermit init .and is typically checked into a repository to make the development tooling required completely by each project self-contained. You can see an example here.It's typically just the former, but I could add the latter for the Flutter package. Actually let me try that now, it might Just Work.
That would absolutely work, thank you. In fact I tried to do this with the Hermit package by setting FLUTTER_ROOT, so doing it with a different envar will be fine.
alecthomas commentedon May 14, 2022
I tried adding the real SDK to the path but it still fails, which makes sense given that it always prioritises the project directory.
alecthomas commentedon May 14, 2022
Interesting, have you special-cased something for Snap?
DanTup commentedon May 16, 2022
I'm a little confused.. I thought
~/Projects/flutterwas outside of your project/repo (eg. a central location for all), but now I'm not so sure. If we added some env var (sayFLUTTER_INIT_SCRIPT) that would allow VS Code to find and run that script if it didn't find an SDK, what would hat path be set to? (considering it presumably needs to be a single value for the whole system, and not per-project)I'm not sure I understand what you tested here - what is
/Users/aat/Projects/startup_namer? I thought the issue was that the Flutter SDK was not being located when not initialised, but this suggests you have two SDKs and the wrong one is being selected.Yep, although it's not something I really want to extend in a non-generic way. I'd prefer to come up with something general that could be supported by many package managers without having each of them specifically coded here.
alecthomas commentedon May 16, 2022
The only SDK present is at
/Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0.~/Projects/startup_namerand ~/Projects/flutter` are both sample Flutter project using Hermit.The only thing that concerns me here is that it's a fallback after the fairly slow failure to search for Flutter. Personally I would prefer an environment variable that specifies exactly where Flutter is, and that be used immediately. Perhaps FLUTTER_SDK_ROOT or something.. I'm not sure.
DanTup commentedon May 16, 2022
Are you able to post (or send to me at
[email protected]) the full log that includes the search? We should not return a folder like~/Projects/startup_nameras the SDK if it is not a valid SDK.My intention for
FLUTTER_INIT_SCRIPTwas something that would only ever occur when Flutter has not been bootstrapped:If Flutter is not bootstrapped:
PATHfinds no valid SDKFLUTTER_INIT_SCRIPTis defined, so it is runPATH)If Flutter is already bootstrapped:
PATHfinds FlutterI'm happy for
FLUTTER_SDK_ROOTto be included in the search (if it's not already), but I don't think that solves the problem here. We need to be a real SDK (or a symlink to) in order for things to work, we can't point at wrapper scripts and not know where an SDK is.alecthomas commentedon May 16, 2022
I included the full log for
~/Projects/flutterin a collapsed section in the original ticket body. The only thing in~/Projects/flutter/binis theflutteranddartshell wrappers, no other Flutter-related files.alecthomas commentedon May 16, 2022
I've subsequently deleted
~/Projects/flutterbut here's what's instartup_namerand the actual SDK root:DanTup commentedon May 16, 2022
Sorry, I missed the original log. I think I see what's happening
/Users/aat/Projects/flutter/bin/flutter/usr/bin/flutteris a symlink to the real SDK location, which we need)hermitin the same directory (/Users/aat/Projects/flutter/bin/hermit)bin/executableoff the end to get/Users/aat/Projects/flutterand then ask "Does this look like a Flutter SDK?" and because it has aflutterbinary in it, it does, so we return it as the SDK (but it's not)So the problem here is that when we followed the symlink, we didn't realise that it didn't point at a
flutterbinary buthermit. This is actually a lot like snap (where it points at asnapbinary) so rather than detectingsnapwith a full path, I'm going to try detecting just the binary name.I'll publish a pre-release build you can test with once the changes are made to confirm it all works (no promises, but hopefully later today).
Handle Snap initialization more generically to support other package …
DanTup commentedon May 16, 2022
@alecthomas can you try upgrading both extensions to the Pre-Release versions (
v2.41.20220516) and restart VS Code and let me know if you still see any issues?It should handle situations correctly now:
bin/flutterbut/Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0has not been set up yet) in which case you should see VS Code say "Initializing Flutter" while it does that/Users/aat/Library/Caches/hermit/pkg/flutter-3.0.0has a complete SDK) it'll detect and use thatYou shouldn't need to set
FLUTTER_ROOT.If anything doesn't work, please capture a new log from this version. Thanks!
[-]VSCode extension unable to find Dart/Flutter using FLUTTER_ROOT if `./bin/dart`/`./bin/flutter` are present[/-][+]Flutter SDK installed via package managers like Hermit are not detected/initialized correctly[/+]DanTup commentedon May 16, 2022
You can switch to the pre-release versions from inside VS Code here:
It may take a few minutes for them to show up as they've only just been published.
alecthomas commentedon May 16, 2022
Success!! Works absolutely flawlessly, thank you :)
DanTup commentedon May 16, 2022
Great! Thanks for confirming!
Handle Snap initialization more generically to support other package …