Lefthook error: flutter command not found - flutter

I switched from GitHub Desktop to Sourcetree due to some missing feature.
On my flutter project, I installed LeftHook to execute a linter when someone commits something.
On GitHub Desktop, Lefthook works well, but when I try to commit from SourceTree, the error sh: flutter: command not found
I can't understand why. The flutter SDK path is set globally correctly (i can use flutter commands in every terminal)

Problem solved!
Seems like that Sourcetree isn't capable to access to the PATH in witch flutter is contained (the one added in the file .zshrc).
So the solution is to add the export in every hook that lefthook uses,
something like this:
#!/bin/sh
export PATH="$PATH:/Users/.../flutter/bin"
if [ "$LEFTHOOK" = "0" ]; then
...

Related

Bazel not running flutter correctly

I'm trying to execute a flutter command using bazel. This is my BUILD.bazel file:
genrule(
name = "flutter_build",
srcs = [
"//:root_filegroup"
],
outs = ["out.txt"],
cmd = "flutter build ipa --export-method development"
)
The command flutter build ipa --export-method development works perfectly if I run it directly in my iterm, but for some reason the same command in bazel returns a permission error:
Flutter failed to open a file at "/Users/rlanhe/tools/flutter/flutter/bin/cache/lockfile".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
Try running:
sudo chown -R $(whoami) /Users/rlanhe/tools/flutter/flutter/bin/cache/lockfile
Well, doesn't make sense to me, since that folder already have correct permission and I'm able to run the command outside bazel.
Integrating Flutter/Dart and Bazel is likely a large amount of work.
There's an issue here about it:
https://github.com/flutter/flutter/issues/19680
And it looks like there are some dart rules here:
https://github.com/cbracken/rules_dart
The immediate issue you're running into is that Bazel runs each action (i.e. build step) in a sandbox, so unless an input to the action is declared, it's not going to be in the sandbox. You can maybe get further by adding tags = ["no-sandbox"] to the genrule, (see https://bazel.build/reference/be/common-definitions#common.tags).
This is essentially running one build system inside another, and this isn't going get the caching and incrementality benefits of Bazel, because Bazel has no insight into what happens inside the genrule. Unless you have some higher-level plans to integrate this into a larger repository that uses Bazel, there isn't much benefit here compared to running flutter directly or in a shell script.

Why `Flutter Doctor` and `New Application Project` fails in my VSCode setup?

Following these directions, like:
Install the Flutter and Dart plugins
Start VS Code.
Invoke View > Command Palette….
Type “install”, and select Extensions: Install Extensions.
Type “flutter” in the extensions search field, select Flutter in the list, and click Install. This also installs the required Dart plugin.
Validate your setup with the Flutter Doctor
Invoke View > Command Palette….
Type “doctor”, and select the Flutter: Run Flutter Doctor.
Review the output in the OUTPUT pane for any issues. Make sure to select Flutter from the dropdown in the different Output Options.
Step 3 of validate instructions results with OUTPUT:
I did install flutter, and flutter doctor in a new command shell gives result:
What am I missing here? I also try VSCode extension palette command Flutter: New Application Project and that also fails with:
Make sure that you have installed Git and that you can access it from the command line. Check your PATH. Flutter SDK directory should be present there.
If that does not work, you should try to reinstall the dart and flutter extension.
Next Step should be to reinstall flutter.
It occurred to me that my attempt to support multiple flutter versions might be going outside of the conventions supported by the Flutter extension for VSCode.
Here's what's up!... If you think you're smart like me and installed different versions of flutter in folders like c:\src\flutter\1.20.2 and c:\src\flutter\1.22.6, then you can forget it because the extension is smarter than us, and will ignore this regardless of our PATH assignment.
Copying contents of my flutter install from c:\src\flutter\1.22.6 to the parent folder c:\src\flutter resolved my issue. I need to review how to easily support different versions of flutter. Hmmm..
BTW... what I realized in retrospect is that the complaint about git is raised by the extension not finding the .git folder under the flutter folder (i.e. c:\src\flutter) that it presumed as the path to my flutter install. Well duh!! That's because I want flutter to be sourced at the versioned sub-folder (i.e. c:\src\flutter\1.22.6). Oh well.
Some scenarios I am left pondering:
How to correctly support multiple flutter installations while also benefiting from the extension (is there a way to configure this extension or my environment as a whole)?
Are my expectations to support multiple flutter installations unreasonable?
If my expectations are reasonable, and there are no known or documented way to support multiple flutter installations while also using this extension, then perhaps the extension has a bug?

I am not able to use flutter as im getting an error with the dart sdk, only it has been working for weeks until today

I am currently having this issue and can't find any solutions that work. Yesterday It was running fine and this afternoon when I wanted to code I received this message in the terminal.
flutter run... Downloading Dart SDK from Flutter engine <<<<<<< HEAD 07c1eed46b9d9b58df78566e9b8b2e42e80d3380
92ae191c17a53144bf4d62f3863c110be08e3fd3
8f89f6505b941329a864fef1527243a72800bf4d... curl: (3) URL using bad/illegal format or missing URL
Failed to retrieve the Dart SDK from: https://storage.googleapis.com/flutter_infra/flutter/<<<<<<< HEAD 07c1eed46b9d9b58df78566e9b8b2e42e80d3380
92ae191c17a53144bf4d62f3863c110be08e3fd3
8f89f6505b941329a864fef1527243a72800bf4d/dart-sdk-linux-x64.zip If you're located in China, please see this page: https://flutter.dev/community/china
I am not using a VPN, am not from china, and as I said this was running yesterday. I have tried reinstalling the flutter package, tried redirecting to redoing the path in Linux, also tried to just clone the github/flutter repo but nothing. Please help
Found that there was an issue with a file in
flutter/bin/internal called engine.version that had the same text as the "head" issue as mentioned in the error code. I have replaced the file with the one from the flutter GitHub repo and the error has gone. will close the issue.
Replace the /flutter/bin/internal/engine.version with the one from this https://github.com/flutter/flutter/blob/master/bin/internal/engine.version
and then run
flutter doctor
I had the same issue, tried everything I found on the internet but nothing worked... Finally, went to the folder where my flutter installation was, deleted the flutter folder, downloaded the flutter sdk again and named the unzipped folder exactly as the previous one: flutter.
This worked for me, so if all else fails, you can try this one.
I was getting that error too. Fixed by fixing the line-endings using the dos2unix utility:
Install dos2unix with sudo apt install dos2unix
Then run this in terminal:
dos2unix ~/snap/flutter/common/flutter/bin/internal/engine.version

How to fix 'No pubspec.yaml file found' when flutter project in OneDrive folder?

Run flutter packages get or flutter run in the root of my project, and it prompts the following
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.
exit code 1
This problem only appears in the project located under the OneDrive folder.
I can run flutter projects elsewhere.
I want to know if someone has the same problem.
After I reinstalled win10 today, this problem disappeared. So I guess this is my personal reason.
There is actually a GitHub issue filed related to your issue. And current status is still open. But there is a workaround to fix this.
The author have been able to resolve the error when the app was moved out from "OneDrive"
Yayy! It worked fine when I moved it out of OneDrive folder. So while
in OneDrive, it works fine until you touch pubspec.yaml. Anyways, all
good now!
There is a possibility that the team is still working on the issue.

Getting Flutter doctor to work

How do I get flutter doctor on my Windows 10 laptop to work, please?
I followed the guidelines here,
Used git to clone the flutter repository,
git clone -b alpha https://github.com/flutter/flutter.git,
Tried adding "C:\Users\<user>\flutter\bin" to my path in the Control Panel
and then in an Admin Powershell, tried executing flutter doctor.
At first, it just hung.
After googling for help, I tried deleting the contents of the
C:\Users\<user>\flutter\bin\cache folder and re-executing flutter doctor but to no avail.
Then, I tried deleting all of flutter and cloning again but flutter doctor just hung again but with, Updating flutter tool.
Tried a few different Googled PATH-adding ideas (that seems to be a complex and disputed area.)
Got a new message: Waiting for another flutter command to release the startuplock
The latest state is that flutter doctor still just hangs but without any message.
I suspect the problem lies in the new Path not being properly recognised (in the registers??)
Can anyone help please?
Well, the issue is not clear enough, but this might be solution, if your flutter doctor is stuck, it might be due to Background Intelligent Transfer Service is disabled, in order to check for yourself, do the following:
Click on the start menu, and then start typing services.
Launch the services and look for Background Intelligent Transfer Service and make sure it is running.
At this stage I believe you will find it disabled for some reason, just right click on it and go to properties and start the service, also change the startup type to automatic.
I can not think of other reasons that might prevent flutter doctor to run for the first time on a Windows machine other than that honestly.
I know this question is a little bit old. Here is a solution that worked for me. Run the Command Prompt as an admin solved the issue for me.
For Windows user check to see if the unzipped flutter folder is read only. (i.e right click the folder then properties then in the attributes section untick the readonly property then apply this change to the folder along with the sub-folders then ok and thats it. Worked for me.
Some errors I got and how I fixed it:
(ERROR 1):
[flutter] flutter doctor -v 'crumb' is not recognized as an internal or external command, operable program or batch file.
Error: Unable to find git in your PATH. exit code 1
(Fix) - Go to flutter installation folder and inside flutter/bin edit the flutter.bat file using a text editor and remove the line (20) that says:
IF EXIST "%mingit_path%" SET PATH=%PATH%;%mingit_path%
The code should look like this on those lines:
REM If available, add location of bundled mingit to PATH
SET mingit_path=%FLUTTER_ROOT%\bin\mingit\cmd
Save and Run flutter doctor and everything should work fine.
(ERROR 2):
flutter doctor takes too long
(Fix) - I downloaded the previous version of the sdk it worked like a charm.
(ERROR 3):
Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this.
(Fix):
Open Android Studio
Tools Menu, SDK Manager
In the window that comes up there are inner panels, choose SDK Tools panel
Tick Android SDK Command-line Tools
Choose Apply button near the bottom of the window
This worked.
(ERROR 4):
The term 'flutter' is not recognized as the name of a cmdlet, function, script file, or operable program.
(Fix) - Put the correct part in the env variables. I had put D:\flutter instead of D:\flutter\bin. That worked.
I got a solution that worked for me
initially i had downloaded the 2.2.5 SDK which gave the forever run error so i went back and downloaded the previous version ie 2.2.2 it worked like a charm
The Flutter SDK is installed in a protected folder and may not function correctly. Please move the SDK to a location that is user-writable without Administration permissions and restart.