Gradle build fails with "Timeout waiting to lock journal cache" in Flutter project


I am trying to run my Flutter project on an Android emulator, but the Gradle build fails before the application starts.

Environment

  • Flutter: 3.44.8 (stable)
  • Dart: 3.12.2
  • Gradle: 8.14
  • Android Gradle Plugin: 8.11.1
  • Kotlin: 2.2.20
  • JDK: OpenJDK 21.0.10
  • OS: Windows
  • Android Studio: latest version

How I run the application

  1. The project is opened in Android Studio.
  2. I select an Android emulator.
  3. I click the Run ▶ button in Android Studio.
  4. I do not run flutter run manually.
  5. The application is not already running when I click the Run ▶ button.

Error

When I run the application, I get the following error:

FAILURE: Build failed with an exception. * What went wrong: Gradle could not start your build. > Cannot create service of type BuildSessionActionExecutor using method LauncherServices$ToolingBuildSessionScopeServices.createActionExecutor() as there is a problem with parameter #21 of type BuildLifecycleAwareVirtualFileSystem. > Cannot create service of type BuildLifecycleAwareVirtualFileSystem using method VirtualFileSystemServices$GradleUserHomeServices.createVirtualFileSystem() as there is a problem with parameter #1 of type FileWatchingFilter. > Cannot create service of type FileWatchingFilter using method VirtualFileSystemServices$GradleUserHomeServices.createFileWatchingFilter() as there is a problem with parameter #1 of type GlobalCacheLocations. > Could not create service of type FileAccessTimeJournal using GradleUserHomeScopeServices.createFileAccessTimeJournal(). > Timeout waiting to lock journal cache (C:\Users\velan\.gradle\caches\journal-1). It is currently in use by another Gradle instance. Owner PID: 19508 Our PID: 23252 Lock file: C:\Users\velan\.gradle\caches\journal-1\journal-1.lock

The error indicates that another Gradle process may be holding the journal-1 cache lock.

Gradle daemon status

From the project's android directory, I ran:

.\gradlew --status

The output was:

No Gradle daemons are running. PID STATUS INFO 16808 STOPPED (by user or operating system) 23252 STOPPED (by user or operating system) Only Daemons for the current Gradle version are displayed. For more on this, please refer to https://docs.gradle.org/8.14/userguide/gradle_daemon.html#sec:status

I also tried stopping the Gradle daemons using:

.\gradlew --stop

The .\gradlew --status command now reports that no Gradle daemons are running, but the build still fails with the same journal-1.lock error.

I also noticed that the lock error reports Owner PID: 19508, but this PID does not appear in the current Gradle daemon status output.

Question

How can I safely identify which process is holding:

C:\Users\velan\.gradle\caches\journal-1\journal-1.lock

and stop that process so that my Flutter Gradle build can run?

Is it safe to delete the journal-1.lock file or the journal-1 cache directory after confirming that no Gradle processes are running?

2
Sep 5 at 5:21 PM
User AvatarGame Pokemon
#java#android#flutter#gradle

Accepted Answer

The owner you found isn't a stale lock. PID 16660 was a live Gradle process that ran alongside your daemon (10512) during the same build and exited when the build failed — that's why jps keeps missing it and why it "disappears" afterwards. Two Gradle processes were hitting the same ~/.gradle/caches at the same time, so one blocked on the other's journal/fileHashes lock until it timed out.

So there's nothing to delete. Don't remove journal-1.lock or the journal-1 folder — that's not the problem, and Windows won't let you delete a file another process is still holding anyway.

The fix is to make sure only one Gradle build touches that cache at a time. When you press Run in Android Studio:

  • wait for any Gradle sync to finish first (the sync is itself a Gradle process);
  • do one clean reset: ./gradlew --stop, close extra Android Studio windows or stray java.exe, then build again;
  • give the IDE and Flutter the same Gradle JDK (Settings → Build, Execution, Deployment → Build Tools → Gradle). On different JDKs you get two separate daemons competing instead of one shared one.

It only shows up on the emulator target because the web build doesn't run Gradle at all, so there's no cache to contend on. The owner you found isn't a stale lock. PID 16660 was a *live* Gradle process that ran alongside your daemon (10512) during the same build and exited when the build failed — that's why `jps` keeps missing it and why it "disappears" afterwards. Two Gradle processes were hitting the same `~/.gradle/caches` at the same time, so one blocked on the other's `journal`/`fileHashes` lock until it timed out.

So there's nothing to delete. Don't remove `journal-1.lock` or the `journal-1` folder — that's not the problem, and Windows won't let you delete a file another process is still holding anyway.

The fix is to make sure only one Gradle build touches that cache at a time. When you press Run in Android Studio:

- wait for any Gradle **sync** to finish first (the sync is itself a Gradle process);

- do one clean reset: `./gradlew --stop`, close extra Android Studio windows or stray `java.exe`, then build again;

- give the IDE and Flutter the same **Gradle JDK** (Settings → Build, Execution, Deployment → Build Tools → Gradle). On different JDKs you get two separate daemons competing instead of one shared one.

It only shows up on the emulator target because the web build doesn't run Gradle at all, so there's no cache to contend on.

User AvatarАндрей
Sep 6 at 6:34 AM
0