35

After upgrading to Android Studio 2.4 Preview 4 I got this error

Error:Could not initialize class com.android.ide.common.util.ReadWriteProcessLock

humazed
  • 74,687
  • 32
  • 99
  • 138

4 Answers4

88

After some research, I found out it's a known bug and fortunately, the solution is very simple.

from release notes:

After updating the Android plugin version, you need to stop the Gradle daemon to apply the update (Issue 267099). Otherwise, Gradle sync and builds fail with the following error:

Could not initialize class com.android.ide.common.util.ReadWriteProcessLock, Failed to notify build listener or java.lang.ExceptionInInitializerError.

To stop the daemon, you can either:

1- restart Android Studio,

or

2- enter the following command in the IDE's Terminal window: ./gradlew --stop or for windows gradlew --stop

Gradle restarts the daemon for you the next time you sync or build your project.

dmSherazi
  • 3,743
  • 5
  • 37
  • 62
humazed
  • 74,687
  • 32
  • 99
  • 138
18

The best way is Invalidate / cache restart or open terminal and type

./gradlew --stop

For windows

gradlew --stop
dmSherazi
  • 3,743
  • 5
  • 37
  • 62
5

This issue is arising in 2.4 version 4 and above to solve this issue you need to stop the Gradle daemon to apply the update (Issue 267099). Otherwise, Gradle sync and builds fail with the following error: Could not initialize class com.android.ide.common.util.ReadWriteProcessLock, Failed to notify build listener, or java.lang.ExceptionInInitializerError. To stop the daemon, you can either restart Android Studio, or enter the following command in the IDE's Terminal window: ./gradlew --stop. Gradle restarts the daemon for you the next time you sync or build your project.

For more information/Source-https://androidstudio.googleblog.com/2017/04/android-studio-24-preview-4-is-now.html

4

Another convenient method:

Android Studio -> File -> Invalidate Caches / Restart... -> Invalidate and Restart

Deni Erdyneev
  • 1,779
  • 18
  • 26