'Unable to run any flutter commands 'The flutter tool cannot access the file or directory'
Whenever I run a flutter command including:
- flutter doctor
- flutter clean
- flutter channel [any channel]
- etc
I get the following error:
Gregorys-MacBook-Pro:~ gregory$ flutter doctor
Unhandled exception:
Exception: Flutter failed to create a directory at "/Users/gregory/.config/flutter". The flutter tool cannot access the file or directory.
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 _throwFileSystemException (package:flutter_tools/src/base/error_handling_io.dart:749:3)
#2 _handlePosixException (package:flutter_tools/src/base/error_handling_io.dart:697:3)
#3 _runSync (package:flutter_tools/src/base/error_handling_io.dart:561:7)
#4 ErrorHandlingDirectory.createSync (package:flutter_tools/src/base/error_handling_io.dart:408:12)
#5 new Config (package:flutter_tools/src/base/config.dart:33:17)
#6 runInContext.<anonymous closure> (package:flutter_tools/src/context_runner.dart:146:21)
#7 AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:104:41)
#8 _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:311:23)
#9 AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:92:20)
#10 AppContext.get (package:flutter_tools/src/base/context.dart:121:32)
#11 config (package:flutter_tools/src/globals.dart:47:30)
#12 getBuildDirectory (package:flutter_tools/src/build_info.dart:673:48)
#13 defaultDepfilePath (package:flutter_tools/src/bundle.dart:29:55)
#14 new BuildBundleCommand (package:flutter_tools/src/commands/build_bundle.dart:24:42)
#15 new BuildCommand (package:flutter_tools/src/commands/build.dart:33:19)
#16 main.<anonymous closure> (package:flutter_tools/executable.dart:102:5)
#17 run.<anonymous closure> (package:flutter_tools/runner.dart:50:13)
<asynchronous suspension>
#18 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#19 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#20 runInContext (package:flutter_tools/src/context_runner.dart:73:10)
<asynchronous suspension>
#21 main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>
Just before I started getting this error I did the following:
- Deleted Library/developer/coresimulator/caches folder
- Changed flutter channel to
beta
I was trying to get disk space for an xcode update.
Solution 1:[1]
My problem was importing a project from Windows. I compared the imported folder with one that was created on MacOS and the difference was that appeared extended attribute. So my solution was to remove the extended attributes via command line:
$ sudo xattr -c -r <project_folder>
Solution 2:[2]
I also faced same issue when i migrate flutter version to 2.0. Only the solution was grant permission to the user for that location.
you may simply run this command :
$ sudo chown -R <username> /Users/<username>/.config
should be replaced with your user name.
Solution 3:[3]
go to flutter sdk folder then,inside bin folder open this path in terminal.now run a command "git stash"
now perform your command "flutter channel beta"
Solution 4:[4]
According to the error listed, ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user. Are you sure flutter is not installed in a directory that requires superuser privileges?
Solution 5:[5]
I am not sure why changing the channel to beta
made the above happen, but what I did to solve it is give myself access to the .config
folder, then changed back to stable
channel.
I am now encountering different problems by flutter commands are working again
Solution 6:[6]
helps on MacOS
sudo chown -R $(whoami) /usr/local/Caskroom/flutter
Solution 7:[7]
This is what worked for me, if you are on Windows follow these steps;
- Go to Windows Security=>Virus & threat protection=>Manage settings=>Controlled folder access=>Allow an app through Controlled folder access .
- Click on Add an allowed app
- Here you can choose either Recently blocked apps or Browse all apps
- Select from the list the apps you want to unblock. Hope this helps
Solution 8:[8]
I had the same issue while using vs code in windows, I just ran vs code as administrator and it solved my problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | arkhos |
Solution 2 | Mahmudur Rahman Shovon |
Solution 3 | Rohit Shukla |
Solution 4 | Dann |
Solution 5 | MrHarvey |
Solution 6 | Tusko Trush |
Solution 7 | Samara20 |
Solution 8 | Rameez88 |