I have an issue with flutter giving out semi-random errors on a larger project when I am performing flutter run. When I run the flutter clean the error went away for the first build, but any consecutive after that gave out an error on part of the gradle process. It happens like this like clock-work, every single time.
So I did some digging into the error, and what I found is that it's related to the flutter.bat with the ampersand exit. I don't know why, or how (judging from the big wall of text, people put some thought into the chaining) but truth be told when I move the exit /b part onto a separate line the error stopped occurring and I was able to perform flutter run consecutively without any errors!
This was the error description I was given:
FAILURE: Build failed with an exception.
* Where:
Script 'D:\SDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 904
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\SDK\flutter\bin\flutter.bat'' finished with non-zero exit value 1
Contents of the flutter.bat
REM To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port:
REM SET FLUTTER_TOOL_ARGS="--enable-asserts %FLUTTER_TOOL_ARGS%"
REM Chaining the call to 'dart' and 'exit' with an ampersand ensures that
REM Windows reads both commands into memory once before executing them. This
REM avoids nasty errors that may otherwise occur when the dart command (e.g. as
REM part of 'flutter upgrade') modifies this batch script while it is executing.
REM
REM Do not use the CALL command in the next line to execute Dart. CALL causes
REM Windows to re-read the line from disk after the CALL command has finished
REM regardless of the ampersand chain.
"%dart%" --disable-dart-dev --packages="%flutter_tools_dir%\.packages" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %* & exit /B !ERRORLEVEL!
When I change the last line into this flutter run started to work.
"%dart%" --disable-dart-dev --packages="%flutter_tools_dir%\.packages" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %*
exit /B !ERRORLEVEL!
I am not quite sure what makes my fix actually work or not work, but I assumed there might be some quirks in cmd.exe that maybe windows not only caches both commands but also cached error level instead of delay evaluating it. Can I safely use this fix or is there some idea on a more proper fix?
I have an issue with flutter giving out semi-random errors on a larger project when I am performing
flutter run. When I run theflutter cleanthe error went away for the first build, but any consecutive after that gave out an error on part of the gradle process. It happens like this like clock-work, every single time.So I did some digging into the error, and what I found is that it's related to the
flutter.batwith the ampersand exit. I don't know why, or how (judging from the big wall of text, people put some thought into the chaining) but truth be told when I move theexit /bpart onto a separate line the error stopped occurring and I was able to performflutter runconsecutively without any errors!This was the error description I was given:
Contents of the
flutter.batWhen I change the last line into this
flutter runstarted to work.I am not quite sure what makes my
fixactually work or not work, but I assumed there might be some quirks in cmd.exe that maybe windows not only caches both commands but also cached error level instead of delay evaluating it. Can I safely use this fix or is there some idea on a more proper fix?