Pretty much as described, I was making a script to automatically clean my build and fresh install my dependencies and accidentally ran flutter clean
as root user. I didn't realize it would be an issue, but flutter gave the following warning before continuing
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
Afterwards, I now can't run flutter clean
or flutter pub get
without superuser privileges
e.g. after flutter clean
:
Flutter failed to delete a directory at "/Users/liamhp/Documents/<my-app>/.dart_tool".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
and flutter pub get
Generating synthetic localizations package failed with 1 error:
Error: Flutter failed to write to a file at "/Users/liamhp/Documents/<my-app>/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart".
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/liamhp/Documents/<my app>/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart
When I run the commands as root, it still seems to work, but I typically want to avoid doing so. What happened here and how can I undo it?
This seems related to the ownership of files and directories on your project. When you run a command as root it most likely created some files that other users are not allowed to modify. you should try running the chown command in the error message, or try deleting any generated files and rebuilding without root. If your code is on git or something like that just delete your code and clone it again.