25

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.

2
  • in your flutter project, try rm -rf build otherwise flutter build clean? Commented Dec 28, 2019 at 12:12
  • 2
    both these commands doesnt work, im using windows. Also, when i press flutter build clean i get Could not find a subcommand named "clean" for "flutter build". Commented Dec 28, 2019 at 14:02

21 Answers 21

35

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.

Sign up to request clarification or add additional context in comments.

1 Comment

is there an explanation as to why flutter can not delete the build folder in this scenario ?
9

If you are using Android Studio then just go to

File->Invalidate Caches / Restart

1 Comment

What about windows ? Can you guide me?
7

Simply run your cmd as administrator then run the command. As simple as that.

Thank me later.. :)

2 Comments

It's not as simple as that, that will not solve this.
Failed to remove build. A program may still be using a file in the directory or the directory itself.
5

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..)

2 Comments

What folder name do you need to search?
You navigate to the folder you are try to delete. When you have it open you search for the exact name of the folder, eg. FolderName2 or ThisIsMyProjectFolder.
3

If it all fails, just restart the computer and you can start from where you left.

Comments

3

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.

Comments

2

Shut down any instances of openJDK or java in task manager, than run it within a cmd window with admin privileges.

Comments

1
  1. Go to Task Manager
  2. search for any Flutter Application running in the Background process, click and End Task
  3. Run flutter clean in IDE

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.

Comments

0
  1. Close your IDE.

  2. Open cmd as administrator by right clicking on Start icon.

  3. Change the directory from C:\Windows\system32> to your flutter directory.

  4. Then run flutter clean

Comments

0

I tried all of the above solutions and the following order worked for me.

  1. Open Task Manager and end any java(JDK) related processes.
  2. Android studio File -> Invalidate Caches / Restart
  3. Once restart the IDE pub get

Comments

0

kill OpenJDK instance from task manager

Comments

0

I had that issue before;

Quit vscode or android studio (whichever you're using) and follow the below steps

  1. Open the command line (CMD) as administrator
  2. Go to the root directory of the project.
  3. run flutter clean command

Comments

0

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

Comments

0
  1. end all the dart processes
  2. delete build folder if not working then also delete .dart-tools, if still not then delete macos\Flutter\ephemera folder

I had to delete all three folder to get out of this

Comments

0

What worked for me:

  1. Restart your PC (some current services block flutter clean)
  2. After restart delete your build folder manually (remove write protection before)
  3. Terminal in VSCode execute this command: flutter clean
  4. Execute this command: flutter pub get
  5. Start your App like always :)

Comments

0

I had the same problem. before cleaning, just stop the running project, then clean

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

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...?

Comments

0

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.

Comments

0

As I did not want to restart my computer, what I did that worked for me was to delete the build folder, and run flutter clean before running flutter pub get.

Comments

-1

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.

Comments

-1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.