Reputation: 803
Whenever I try to clean my flutter project by using the command
flutter clean
I get an error saying
Failed to remove build. A program may still be using a file in the directory or the directory itself. To find and stop such a program, see:
https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used
I can understand that there is some directory opened and it has to closes in order to clean. But I cannot understand which one is it. I tried restarting my computer to resolve this issue. But still when I run the command flutter clean I get the error.
Upvotes: 24
Views: 58939
Reputation: 487
I've had this issue for months and couldn't figure it out until now. It was nothing to do with Google Drive or any other process using the folders.
The issue was the naming of the root directory. My project path was like so:
some_other_folder/actual-main-folder
It seems that it doesn't like the character "-" and it doesn't say anything about it when running flutter doctor or any other command.
I changed it to:
actual_main_folder
Where the "-" was replaced by "_" and that fixed everything. No more permissions issues or folders that can't be deleted because they're in use etc.
Hope this helps someone.
Upvotes: 0
Reputation: 11
After following the above steps, like closing instances and clean steps, if you still can not delete, May be check is there android studio or emulator or flutter app running...?
Upvotes: 0
Reputation: 1
I had the same problem. before cleaning, just stop the running project, then clean
Upvotes: 0
Reputation: 52
What worked for me:
Upvotes: 0
Reputation: 2795
I had the same problem.
What worked for me was stop anti virus program running on my PC
Then flutter clean worked fine.
After that I restated anti virus program.
Upvotes: -1
Reputation: 1
I had to delete all three folder to get out of this
Upvotes: 0
Reputation: 1
flutter lib folder and all dart file major red lines in vscode so use this two commands flutter clean and flutter pub get it's work but if your error android folder then you use other way to solve the problem
Upvotes: 0
Reputation: 1
I had that issue before;
Quit vscode or android studio (whichever you're using) and follow the below steps
flutter clean
commandUpvotes: 0
Reputation: 6363
I tried every answer from here and then I found out it was my Avast antivirus.
Avast Antivirus (others too maybe) is notorious to block such development activity. You've to add all the SDK and project containing folders in exceptions then it works.
Upvotes: -1
Reputation: 716
Try to delete build folder manually. If it shows using a file in the directory error
then identify the process and kill or simply restart machine.
Then run flutter clean
and flutter pub get
Additionally try invalidate cache in IDE.
Upvotes: 3
Reputation: 599
The Reason was Flutter Clean cant delete the build while the Application is still running in the Background process, u have to close it and run.
Upvotes: 1
Reputation: 297
If it all fails, just restart the computer and you can start from where you left.
Upvotes: 3
Reputation: 529
I tried all of the above solutions and the following order worked for me.
Upvotes: 0
Reputation: 61
Shut down any instances of openJDK or java in task manager, than run it within a cmd window with admin privileges.
Upvotes: 2
Reputation: 1238
Close your IDE.
Open cmd as administrator by right clicking on Start icon.
Change the directory from C:\Windows\system32>
to your flutter
directory.
Then run flutter clean
Upvotes: 0
Reputation: 577
If you moved your project folder to another place then just **delete** your "build" folder
and
flutter clean
and
flutter pub get
you will be fine:) Cheers.
Upvotes: 34
Reputation: 264
If you are using Android Studio then just go to
File->Invalidate Caches / Restart
Upvotes: 9
Reputation: 305
Simply run your cmd as administrator then run the command. As simple as that.
Thank me later.. :)
Upvotes: 7
Reputation: 865
The answer is found in the link u were sent to go to which was https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used
Apparently, you need to download Microsoft's Process Explorer to help you figure out which program is that.
It will let you know which app is handling that folder and you will also be able to kill that handle.
Find -> Find handle -> search for folder's name (will take a while..)
Upvotes: 5