Unable to run any flutter commands 'The flutter tool cannot access the file or directory'

Viewed 13080

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.

8 Answers

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> 

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.

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"

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?

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

I had the same issue while using vs code in windows, I just ran vs code as administrator and it solved my problem.

helps on MacOS

sudo chown -R $(whoami) /usr/local/Caskroom/flutter

This is what worked for me, if you are on Windows follow these steps;

  1. Go to Windows Security=>Virus & threat protection=>Manage settings=>Controlled folder access=>Allow an app through Controlled folder access .
  2. Click on Add an allowed app
  3. Here you can choose either Recently blocked apps or Browse all apps
  4. Select from the list the apps you want to unblock. Hope this helps
Related