Process Monitor Finds the Real Cause

Flutter’s Pub failed to delete entry: Process Monitor Finds the Real Cause This guide provides the definitive solution to the Flutter Pub failed to delete entry because it was in use by another …

Back to all articles

This guide provides the definitive solution to the Flutter Pub failed to delete entry because it was in use by another process error.

Resolving dependencies... (1.4s)
Downloading packages... (3.4s)
Pub failed to delete entry because it was in use by another process.
This may be caused by a virus scanner or having a file
in the directory open in another application.
Failed to update packages.

If you’re a Flutter developer on Windows, you’ve probably felt that unique, hair-ripping frustration when you run flutter pub get and are met with this vague, unhelpful message.

Your mind immediately starts racing through the checklist. “It’s not a virus scanner,” you mutter, “I’ve been working on this for hours.” You’ve already tried everything: rebooting, closing your IDE, running flutter clean, maybe even flutter pub cache repair.

Yet the error persists, mocking you.

This article is for you. It’s the result of a real, multi-hour troubleshooting session that went through every failed suggestion and finally landed on the one tool that doesn’t guess: Process Monitor.

We’re going to stop the cycle of frustration and learn how to find the exact process causing the lock in under five minutes.

BONUS: Jump to Saropa’s deep cleaning script for stubborn Flutter caches

Why Standard Advice Fails

The internet is filled with well-meaning but often ineffective advice for this error. It usually involves a series of escalating rituals:

  1. The Quick Fixes: Close VS Code and Android Studio. Restart your machine. Run your terminal as an administrator.
  2. The Clean-Up Crew: Delete the .dart_tool folder. Delete pubspec.lock. Run flutter clean.
  3. The “Nuke It” Option: Run flutter pub cache repair or manually delete the entire flutter_cache (or \User\AppData\Local\Pub\Cache) folders.

The problem is that these are all shots in the dark. They operate on the assumption that your issue is simple cache corruption or a lingering dart.exe process.

But when the cause is more stubborn — a background service, a file indexer, or even a bug in a package itself — these steps do nothing but waste your time. You’re treating the symptom (a locked file) without ever diagnosing the disease.

Introducing Process Monitor (ProcMon)

Process Monitor is a free, official Microsoft tool from the Sysinternals suite. It’s like a flight recorder for your operating system, showing you every single file system, registry, and network activity in real-time. Instead of guessing what’s touching your files, you can simply watch and see.

This is our shortcut. This is how we end the guesswork.

Finding the Locking Process with ProcMon

Step 1: Download and Setup

First, get the tool. Download it directly from the Microsoft site, extract the zip file, and run ProcMon.exe. There’s no installation required. When it opens, it will immediately start capturing data.

Process Monitor screenshot
Process Monitor screenshot

Click the magnifying glass icon on the toolbar to stop the capture for now.

Step 2: Setting the Right Filters (The Most Important Step)

ProcMon captures thousands of events per second. To make sense of it, we need to filter out 99.9% of the noise.

Go to the menu Filter -> Filter… and set up a simple rule to only show us activity from Dart’s command-line process.

  • Set the filter to: Process Name | is | dart.exe | Include
  • Click Add, then Apply, then OK.
The filter window
The filter window

This single filter is our entire setup. We are now watching only what Dart is doing to the file system.

Step 3: Running the Capture & Finding the “SHARING VIOLATION”

Now we’ll perform the sting operation.

  1. Clear the Display: Click the eraser icon on the toolbar to clear any old events.
  2. Start Capture: Click the magnifying glass icon to begin capturing.
  3. Trigger the Error: In your terminal, run flutter pub get and wait for it to fail.
  4. Stop Capture: As soon as the error appears, go back to ProcMon and click the magnifying glass again to stop capturing.
  5. Find the Error: Press Ctrl+F to open the Find dialog. Search for the text SHARING VIOLATION.

ProcMon will instantly jump you to the exact moment dart.exe failed to delete a file. This is our smoking gun.

By “instant”, we mean up to 5 minutes ..

The Result column will show SHARING VIOLATION, and the Path column will show you the exact file that is locked (e.g., …\AppData\Local\Temp\pub_random\package-x.y.z.tar.gz).

Step 4: Unmasking the Culprit

You know the file. Now to find who locked it.

  1. Reset Filters: First, go to Filter -> Reset Filter to remove our dart.exe rule.
  2. Filter by Path: In the log, find the row with the SHARING VIOLATION. Right-click on the file path in that row and, from the context menu, choose Include.

The log will now be filtered to show every single process that touched that specific, problematic file. Reading this short list from top to bottom will tell you the story:

  1. dart.exe creates the file.
  2. SomeOtherProcess.exe reads or scans the file. ← This is your culprit.
  3. dart.exe tries to delete the file and gets the SHARING VIOLATION.

The culprit is often MsMpEng.exe (Windows Defender), another third-party antivirus, or a cloud sync client. You can now take targeted action, like adding a specific process or folder exclusion to your antivirus settings.

Case Study: When the Culprit is a Broken Package

Sometimes, the culprit you unmask isn’t an external process. In the real-world case that inspired this article, the problem was a bug inside the speech_to_text package itself.

Version 7.2.0 had an issue on Windows where it would lock its own files during extraction.

This is where our final trick comes in. If you find yourself in this situation, you need to forbid Flutter from ever touching the broken version.

You do this with dependency_overrides in your pubspec.yaml.

# pubspec.yaml

dependencies:
  # This might be what you want, but a transitive dependency
  # could be pulling in a broken version.
  speech_to_text: ^7.1.0 

# Add this section at the end of the file to take control.
dependency_overrides:
  # This is a direct command: "Use ONLY this version. I don't care
  # what any other package wants."
  speech_to_text: 7.1.0

After adding the override, run flutter pub cache repair to clear out any corrupted downloads, then run flutter pub get again. This combination is a surgical fix for when a package, not your environment, is the problem.

Stop Guessing, Start Diagnosing

The “in use by another process” error feels like a curse because it provides no information. But with the right tool, it’s just another bug. Stop wasting hours rebooting and deleting folders.

So, the next time you see this error, don’t guess. Launch Process Monitor, set your filter, and get your answer in minutes.

“Without data, you’re just another person with an opinion.” — W. Edwards Deming

BONUS: Powershell Flutter Cleaning script

Tweak the paths then review (i.e. pass through your AI!)

Sources:


Final Word 🪅

Illustration from article
saropa.com
Share this article

Your feedback is essential to us, and we genuinely value your support. When we learn of a mistake, we acknowledge it with a correction. If you spot an error, please let us know at blog@saropa.com and learn more at saropa.com.

Originally published by Saropa on Medium on July 15, 2025. Copyright © 2025