与描述的一样,我正在制作一个脚本来自动清理我的构建并全新安装我的依赖项,并意外地以 root 用户身份运行
flutter clean
。我没有意识到这会是一个问题,但 flutter 在继续之前给出了以下警告
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
之后,如果没有超级用户权限,我现在无法运行
flutter clean
或 flutter pub get
例如
flutter clean
之后:
Flutter failed to delete a directory at "/Users/liamhp/Documents/etch-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.
和
flutter pub get
Generating synthetic localizations package failed with 1 error:
Error: Flutter failed to write to a file at "/Users/liamhp/Documents/etch-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/etch-app/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart
当我以 root 身份运行命令时,它似乎仍然有效,但我通常希望避免这样做。这里发生了什么以及我该如何撤消它?我已经尝试卸载并重新安装 flutter
这似乎与项目中文件和目录的所有权有关。当您以 root 身份运行命令时,它很可能会创建一些不允许其他用户修改的文件。您应该尝试运行错误消息中的 chown 命令,或者尝试删除任何生成的文件并在没有 root 的情况下重建。如果您的代码在 git 或类似的东西上,只需删除您的代码并再次克隆它即可。