1

Whenever I run flutter doctor in my terminal (without admin priviledges) with either C:\Program Files\Git\bin, ```C:\Program Files\Git\cmd`` or any path containing the git executable, the cmd closes instantly.

If I run the command on cmd with admin priviledges, it works. If I run the command on cmd without any git dir added to path, it works. I run Windows 11 and I have powershell 7.3.2 installed.

I have seen similar issues like this and others, tried the several solutions in their threads but none seems to work.

flutter doctor -v output (when run without git in Path):

[√] Flutter (Channel stable, 3.7.5, on Microsoft Windows [Version 10.0.22000.613], locale en-US)
    • Flutter version 3.7.5 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c07f788888 (8 days ago), 2023-02-22 17:52:33 -0600
    • Engine revision 0f359063c4
    • Dart version 2.19.2
    • DevTools version 2.20.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\HP\AppData\Local\Android\sdk
    • Platform android-UpsideDownCake, build-tools 33.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)

[√] VS Code, 64-bit edition (version 1.76.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.60.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.613]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 110.0.5481.178
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 90.0.818.66

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
Quwaysim
  • 351
  • 3
  • 11

3 Answers3

2

A more detailed explanation for those who are wondering what's going on here.

When you run flutter from the Windows Command Line, it invokes flutter.bat, which includes within it a bunch of tests of your environment that call EXIT 1 if they fail. This kills not just the batch file you ran, but also the the command line process you ran it from. Normally, you would use EXIT /b 1 to exit only the batch file, but the design of flutter.bat and some assumptions about how it will be used means that this results in a retry loop.

Since there a bunch of tests in flutter.bat that could be failing, it's unclear which of them is causing trouble, and there are a lot of answers online to the problem of flutter failing like this that suggest fixing your paths to make sure git or something else is in your path (as this not being the case triggers some earlier tests). Quwaysim's answer corresponds to a test that fails in FLUTTER_HOME\bin\internal\shared.bat (which is invoked by flutter.bat) because of relatively recent changes to git that are described in the article they link.

That test tries to run git rev-parse HEAD in your Flutter directory to get the specific version of Flutter you have installed. However, if git thinks that the repository in your Flutter directory is unsafe, it will write an error message to STDERR. Since the batch file is looking for output on STDOUT and gets none, it assumes that git is not installed, prints that message accordingly, and does a hard exit. The STDERR output includes the suggestion given, but you never get shown this message.

Diagnosing this problem was (for me) a matter of working through the batch file that's invoked to find out where it was actually failing. Then, by running that command myself on the commandline, I was able to see the error text and work

0

I found the solution:

So I noticed that after I added this line in my path

C:\flutter\bin;C:\Program Files\Git\bin;C:\Windows\System32\

as posted here by Metaller, on running flutter doctor, I got a warning:

fatal: detected dubious ownership in repository at 'C:/Users/abc/Projects/my-awesome-project'
'C:/Users/abc/Projects/my-awesome-project' is owned by:
        'S-1-5-32-544'
but the current user is:
        '<my-current-user>'
To add an exception for this directory, call:
        git config --global --add safe.directory 

I ran git config --global --add safe.directory C:\flutter in my powershell (make sure it's powershell - preferred you download powershell 7), removed C:\flutter\bin;C:\Program Files\Git\bin;C:\Windows\System32\ from path, added my git exe dir C:\Program Files\Git\bin back to path and everything started working just fine.

If you'd like to know more about the git safe dir issue, read this article by Dennis.

Quwaysim
  • 351
  • 3
  • 11
  • I cannot determine from the above submission, if this is supposed to be a solution to your asked question, (please clarify). Your error above, shows that you are not running your code elevated, or as a member of the Administrators group. Also `C:\Windows\System32` should already be, by default included in your `Path` variable. If you are adding it here, it is either not needed, or you have previously corrupted the content of `Path`, (and should fix it). – Compo Mar 03 '23 at 17:11
  • It's the solution, I have updated the post. I don't think I need to run the command elevated. The error that came from git is a security update in git v2.35.2 or later. You can check the article I attached in the solution above. Thank you. – Quwaysim Mar 03 '23 at 17:48
  • I have no idea either, all I'm saying is a message saying `fatal`, and including details showing the SID for the Administrators group, `S-1-5-32-544`, seems like you need should be performing this within that group. – Compo Mar 03 '23 at 17:54
0

I had the same problem and it is solved after moving flutter sdk from D:/ Drive to C:/ and also changing flutter path in user environment variables to the new path.