Can't load Kernel binary: Invalid SDK hash in Flutter - flutter

Whenever I try to run a dart tool like Dart Migrate I get the following error and I am unable to run that tool. Is there a way to solve this problem or I have to reinstall Flutter?
Btw every thing is okay with Flutter Doctor

After a lot of effort and wasting a lot of time on this issue I have been able to solve this problem. I have installed dart-sdk separately in the past and place the path of that dart-sdk at the top (before flutter one) in environment variables PATH. So I deleted that old dart-sdk path and deleted the respective folder this solved my problem.

In VS Code, if you get "Can't Load Kernel binary: Invalid SDK Hash" in Flutter or Dart, update dart.sdkPath setting
If you get this in VS Code, in addition to re-downloading the dart-sdk, make sure the "dart.sdkPath" setting in user/workspace settings is pointing to the new SDK. In my case, even though I had it in my path as in Junaid's answer, VS Code was still looking to the old dart-sdk folder and giving me the kernel hash error. I updated the dart.sdkPath to the correct path and restarted VS Code:
For example, in Windows:
Download dart sdk
Unzip it to c:\tools\dart-sdk or any other folder (make sure you rename or delete the existing dart-sdk folder)
ctrl-shift-p, type 'user settings (JSON)', open the json settings, and add:
"dart.sdkPath": "C:\\tools\\dart-sdk",
Update your system PATH environmental variable to point to the new dart-sdk and delete the reference to the old location.
Restart VS Code.

Note that Instead of This "dart.sdkPath": "D:\Dart\dart-sdk\bin" work well for me.
path should be included '\bin' also. It work for me

Related

Unverified breakpoint in VSCode in Flutter

My debug mode does not work as I see the unverified breakpoint notice in VSCode in debug mode.
I already checked the Launch json file and it is fine, but something else is wrong which I do not see what it is. Maybe something related to paths, etc.
I tried to make a new project in VSCode using the command and the new default Flutter project is OK.
So it seems like, if I can make a fresh project from my current project then my problem could be solved. But how? I tried to move my files from my current project to the newly made Default Flutter project but I do not think this is the way. Because I guess some of the files in my project are the source of issues...
I already deleted .vs file but no help.
Do you have any good idea how to fix this issue?
First try cleaning the project files using flutter clean then flutter pub get, try running the app without debugging and if you are down for making a new one just move the lib and assets folders and copy the content of pubspec.yaml file.

How to delete then reinstall Flutter

Whenever I have a problem with Flutter I often find answers saying 'reinstall the Flutter SDK'.
However I cannot find any clear instructions on how to do this (please direct me to them if I am wrong).
General Questions
By 'clear' instructions, I mean ones that answer the following questions:
What folder(s) should be deleted to remove Flutter from my computer?
Do any files need to be copied and added to the new Flutter folder once I reinstall it?
Do I need to make any changes to my Flutter projects either before or after reinstalling Flutter?
Will I need to download the same channel (stable, beta, dev, master) as what I am currently on?
Will I need to make any changes to my PATH?
Are these the correct steps to reinstall?
Go to https://flutter.dev/docs/development/tools/sdk/releases?tab=macos
Download the zip of the release you want (safest to use latest stable version)
Open Flutter zip in SAME location as the previous Flutter folder was
Done - I should now be able to run Flutter projects without any further steps
Apologies if these seem like very basic questions but for someone fairly new it isn't obvious what the answers are.
I'm new to Flutter and had similar issues. I will outline what worked for me but meanwhile, to answer your questions:
What folder(s) should be deleted to remove Flutter from my computer?
The Flutter folder which you unzipped and, presumably added to $PATH. Although not deleting it isn't going to pose an issue. I have separate folders of different versions of Flutter on my computer and it's fine.
Do any files need to be copied and added to the new Flutter folder
once I reinstall it?
Try a fresh download of Flutter and unzip it? There is no need to copy or add any files to the Flutter folder once you've (re)installed it.
Do I need to make any changes to my Flutter projects either before or
after reinstalling Flutter?
Not exactly sure what you mean by make changes to your Flutter projects. If you ran flutter doctor and didn't get any errors, then it's good to go. When you create a new Flutter project either in Android Studio, VS Code or Terminal, it will automatically handle whatever file copying business.
Will I need to download the same channel (stable, beta, dev, master)
as what I am currently on?
No, you only need one. I suggest you download one from Stable unless you need web support, which would be Beta.
Will I need to make any changes to my PATH?
After you've unzipped your fresh copy of Flutter (note the folder destination), open Terminal and change the path to said folder destination but make sure it's the /bin folder you're mapping to.
Are these the correct steps to reinstall?
Go to
https://flutter.dev/docs/development/tools/sdk/releases?tab=macos
Download the zip of the release you want (safest to use latest stable
version) Open Flutter zip in SAME location as the previous Flutter
folder was Done - I should now be able to run Flutter projects without
any further steps
Yes and no. You're missing a number of steps. Please follow the full Flutter installation guide depending on your OS.
It took me about 10 hours over two days and a VPN to finally get it working in China with an old install from two years ago when I was in Montréal.

'flutter doctor' returns '\flutter\bin\cache was unexpected at this time.'

I have downloaded flutter_windows_1.17.1-stable and extracted it outside the program files, yet whenever I run the 'flutter doctor' command I am getting the message '\flutter\bin\cache was unexpected at this time.'
I have searched about this and found few solutions suggesting to delete the cache folder in bin of flutter directory, I did that, also added the path in environment variables, still having the same message.
Please, I need suggestion on how to fix this.
Thank you.
Faced similar issue, I initially created C:\Program Files(Manual)\Flutter
and added to user env path variable, but got Cache error, only when I moved to c:\src\Flutter it worked, I'd say paths with spaces (and or special chars '(' ')' ' ' aren't accepted
While you're using windows, go to the system environment variables from the search and edit flutter path variable, change it to the binary folder like C:\src\flutter\bin.
When I ran into this issue, I had already installed flutter several times to fix previous errors. This issue can happen if flutter is not installed in your environment variables, but it also happens if there is another duplicate or path to another bin in the same host. Also, make sure to check on all places for duplicate paths to two or more flutter bins. There are environment variables for your account, and environment variables for the entire PC. Be sure to check in both
Make sure you extract all your files to c:/src/flutter
If the problem is still there , then to run commands use c:/src/flutter/bin
I.e., include bin to your path
I had the same issue. I tried all the above solutions, but they did not work. So I also changed the path. The solution was to direct the CMD to Flutter's main directory.
Example: You want to run the code flutter doctor. You expect to open the CMD and run the code, so you get the result while you have configured the env and path, but it does not. To run the code, go to the same directory you installed the flutter and then run your codes;
E:\Program Files\flutter> flutter doctor
I hope it works for you as it worked for me. GL
1.) Move the Flutter folder to your C Drive.
2.) Create a new Folder called "src".
3.) Move Flutter folder to src.
4.) Add C:\src\flutter\bin to Path in Control Panel -> User Accounts -> Enviorments -> Path -> edit
first if you changed your flutter's location and if you gave path again to variables, you you need to dalate old path of flutter and it works.

How to develop Flutter app and related package at same time in VS Code

I have a Flutter app and a package folder loaded in VS code at the same time within a workspace. What entry do I need to make to my app's pubspec.yaml file to ensure that changes I've made to the package are compiled and included whenever I hot reload or restart the app? What would be an alternate strategy if this is not possible?
If your pubspec.yaml refers to your package with a path then I would expect this to happen automatically. If not, I would consider it a bug. Please file an issue at https://github.com/Dart-Code/Dart-Code and include a log file generated by running the Dart: Capture Logs command and as much info about your project layout as possible (a clonable repo to repro would be perfect).

Flutter installation not working?

I have installed the flutter folder in Program Files (x86) and have added the .../flutter/bin directory to path. Running flutter doctor in the flutter_console.bat window or just a normal command prompt window gives nothing
and running as admin in either gives me the error:
Updating flutter tool...
\flutter\.pub-cache was unexpected at this time.
What do I do? Thanks in advance for any help.
You shouldn't put Flutter in Program Files. These folders are not writeable by non-Admin users so may fail when trying to write files if you're not running your console/editor as Admin.
Cut flutter folder from Program Files (x86) to Program Files. It has problem with x86 but works fun in x64 directory. And update the environment variables with the new path.
I had mine fixed by just removing the special character from the directory name.
I organize my folders with numbering and parenthesis like so
1) xyz
2) yza
3) aws
...
25) flutter
I changed it to
1) xyz
2) yza
3) aws
...
25 flutter
don't forget to change it in environment variables too
Ok so this is probably not the way to go about it but what I did to solve this problem was remove this line
SET pub_cache_path=%FLUTTER_ROOT%\.pub-cache
from flutter/bin/flutter.bat. I then went through the installation process and once everything was working changed the flutter.bat file back by adding the line again and then ran flutter again. I got no errors from doing this and I appreciate that this is probably not the correct way to go about solving this problem but it worked for me so I am posting it as the answer if others want to try it.
1.Set the environment variable by copying the bin directory ex: C://programfiles/flutter/flutter/bin
2.Go to Control panel -> User Accounts -> User Accounts-> Change environment variables -> Choose User variable -> Path -> Edit -> New -> Paste the link -> click ok
3.Restart Computer -> Open powershell -> Type "Flutter"
4.It should be working now.
1- First make sure that you running cmd or powershell as admin.
2- If didn't work try to restart PC.
3- If didn't work try to move the flutter folder to another path and make sure that you did the required changes on Environment Variables.
4- If didn't work, just delete the cache folder in "flutter\bin" and try again by writing
flutter doctor
Also as a note, try not to put your flutter directory inside the special directories which need a special permissions like Program Files.
I had originally installed it in d:\Program Files (x86) which is NOT the system folder, but an alternate install location that does not require elevated privs, and I was getting this error. I moved flutter to just d:\flutter and it worked. I don't know if it was spaces or the parentheses that was problematic.
Extract the zip file and place the contained flutter in the desired installation location for the Flutter SDK (for example, C:\src\flutter; do not install Flutter in a directory like C:\Program Files\ that requires elevated privileges).
You are now ready to run Flutter commands in the Flutter Console!