9

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.

Jithin Pal
  • 487
  • 1
  • 4
  • 14
  • in your flutter project, try `rm -rf build` otherwise `flutter build clean`? – EvOlaNdLuPiZ Dec 28 '19 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".``` – Jithin Pal Dec 28 '19 at 14:02

13 Answers13

15

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.

imssurya
  • 329
  • 3
  • 7
8

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

Thank me later.. :)

Talha Shahab
  • 173
  • 1
  • 5
7

If you are using Android Studio then just go to

File->Invalidate Caches / Restart

Abdul Rauf
  • 214
  • 3
  • 4
3

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

EngineerDanny
  • 658
  • 9
  • 11
2

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.

1

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

evan
  • 51
  • 1
  • 11
1

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

McWally
  • 79
  • 3
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.

aihamhasan
  • 249
  • 5
  • 8
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

Maruf Hassan
  • 925
  • 11
  • 21
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
King Alawaka
  • 477
  • 4
  • 3
0

kill OpenJDK instance from task manager

Hamza Abdullah
  • 186
  • 1
  • 4
  • 18
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
Sanket Shah
  • 4,448
  • 3
  • 19
  • 40
-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.

Lalit Fauzdar
  • 5,109
  • 2
  • 21
  • 45