Error:Unexpected lock protocol found in lock file. Expected 3, found 0

AndroidGradleAndroid Gradle-Plugin

Android Problem Overview


After upgrading Android Studio to 1.3, I can't compile my project anymore. I am getting Unexpected lock protocol found in lock file. Expected 3, found 0.. I have tried with deleting my .gradle folder but that does not solve the problem. Anything else I can do?

Android Solutions


Solution 1 - Android

I have solved it by deleting the folder

> c: \ users \ [myusername] \ .gradle \ caches \ 2.14.1

After reopening Android studio it was all fine

Solution 2 - Android

okay here's very lightweight solution with steps:

  • Ctrl+Alt+Shift+S or File->Project Structure

  • Select Project from left panel

  • Now check your Gradle Version at right panel

  • In my case my Gradle Version is 3.3

  • Navigate C:\Users\ashish\.gradle\caches and delete your Gradle Version - 3.3 named folder.

  • Now restart or open your project again from workspace.

Greetings...your problem is solved.

Solution 3 - Android

Go into your local file project and search for the ".gradle" folder

Erase it and restart your IDE

Solution 4 - Android

You must erase /.gradle folder from user directory, not from project, it`s a hidden directory, if you used linux-based system it is in /home/user/.gradle and press "alt"+"." to show hidden folders

Solution 5 - Android

Deleting cache folder take long time because it have more than 200k files which is more than 3GB. There is quick view as Ashish mentioned.

I also faced this error in only one app.

Go through the step.

  1. In you project open gradle-wrapper.properties file. Which is located in Gradle Script in Android structure. As shown in below image.

enter image description here

  1. In that file check distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip. Here gradle version is 4.6.

enter image description here

3.So all cache for that project will be store in your C:\Users\Your PC Name or User Name\.gradle\caches\4.6. As shown in below image.

enter image description here

  1. Close your android studio and delete the 4.6 folder. After deletion open android studio.

That's all. It took mine 6 hours to figure out and deleting cache folder. So I decide to post this answer. So people will not waste same time.

Solution 6 - Android

In android studio, Click on the "Invalidate caches/Restart.." and confirm.

Solution 7 - Android

Delete C:\Users\user\.gradle\caches folder and restart the project.

Solution 8 - Android

I had the same problem. And deleting the project's .gradle folder didn't fix the problem.

I solved the problem by deleting the C:\Users\<username>\.gradle folder and made studio refresh the entire gradle build. I found I had 4 different versions of gradle installed from my upgrade path.

Solution 9 - Android

This happened after my computer froze and I had to force it to restart. To fix it, I ran this and then everything worked. No Android Studio restart required:

cd path/to/.gradle/
find . -name "*.lock" -delete 

Solution 10 - Android

From File menu click on Invalidate Cache / Restart. And then Click on Invalidate and Restart. It will fix your problem.

Invalidate Caches

Solution 11 - Android

I faced the same problem in Android Studio 4.0.1 when my computer froze and I had to force shut down.

What I did to resolve the issue was delete .gradle folder from the project directory and build the project again.

  1. Open the Project pane, if not open already.
  2. Select the Project view (not Android) from the drop-down menu
  3. The first folder (in red colour) will be .gradle, Right Click > Delete.
  4. Build the project again.

enter image description here

Solution 12 - Android

All of these solutions did not work for me on Android Studio 2.1. What worked was me opening gradle-wrapper.properties in project folder and changing my gradle reference on the line below:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

This was changed to:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip

After which gradle upgraded and the app started working!

Solution 13 - Android

We successfully resolved this error.. Go to your project location in my case it was F:=> PROJECT NAME=> .gradle.. and we deleted the the .gradle file.. then restarted android studio and loaded the project again.. and this time the the gradle build successfully.

Solution 14 - Android

In my case, GRADLE_USER_HOME was not set due to a machine change. After re-setting this env variable, everything works fine again.

Solution 15 - Android

You dont need to delete all your gradle files. Your just need to delete C:\Users\(your user name)\.gradle\daemon\(gradle version)\registry.bin.lock and you are done!

Solution 16 - Android

  1. Get into the .gradle folder in the root of the project.

  2. There, you might see a couple of versions. Pick the gradle version that you're using in the porject.

  3. cd into taskArtifacts folder.

  4. clear the cache.properties.lock file.

Finally, build the project. Hope that helps.

Solution 17 - Android

None of the above worked for me ....

You just need to go to File -> Project Structure or jus press Ctrl+Alt+Shift+S

and then on the top left click Project Make sure that your Android Plugin Version is the same as you Android Studio Version .. This should fix it

additionally

You can also create a new Project and check under Project view initially you'll be in Android .. change the view to ... Project - > gradle (Note .. not .gradle only gradle ) ->wrapper ->gradle-wrapper properties.. open this file and you can see the last line ie ..

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

make sure you have the same gradle version in your old files as well

Check out this Youtube Video i made regarding this issue

https://youtu.be/-Ngn4YvbKtw

Solution 18 - Android

None of the above resolutions worked for my instance of this error. I had just started the project, so I really wasn't concerned about the loss of it. I completed the following:

  1. Selected "File\Close Project" and the project closed.
  2. The opening screen to create a new project came up.
  3. I deleted the project from the list just to have it not show in the list.
  4. Created a new project with a slightly different name.
  5. Ran the new project and it worked fine.

Solution 19 - Android

Go into your local file project and search for the ".gradle" folder,(folder from user directory, not from project, it`s a hidden directory, if you used linux-based system it is in /home/user/.gradle and press "alt"+"." to show hidden folders,)

  • Erase it and restart your IDE

if this doesnt work then, All of these solutions did not work for me on Android Studio 2.1. What worked was me opening gradle-wrapper.properties in project folder and changing my gradle reference on the line below:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

This was changed to:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip

After which gradle upgraded and the app started working!

Solution 20 - Android

Open your previous project and open file>ProjectStructure>project check this gradle version,android plugin version of previous project and set it to your current project .and click invalidate/restart

Solution 21 - Android

For the persons who have this problem on <Android Studio 3.1.2>. After I got this problem, I done all solutions in this topic. But each of the solutions alone did not solve my problem. So I've combined some strategies.


  1. First I removed application from Android Studio Launcher List.
  2. Second I deleted all the content from .gradle (FOLDER FROM USER DIRECTORY).
  3. Third I import the project again (after sync i got the error again).
  4. Fourth while project is open I used <Invalidate Cache / Restart> option from FILE menu.

I hope this solution work for you too.

Solution 22 - Android

Removing the .gradle directory from the user directory is not enough. Make sure to delete the .gradle directory from the project directory as well. In fact I would start with the project and only if that isn't enough should you delete at the user level.

Solution 23 - Android

In android studio, Click on File and then Click "Invalidate Caches/Restart" and then confirm.

Solution 24 - Android

  1. Go to File -> Project structure
  2. Select Project
  3. On the right panel change the Gradle Version

I was on 5.6.4 when this problem occurred and I downgraded it to 5.1.1. Sync the project and it should work after that.

Solution 25 - Android

Changing the gradle version from project structure worked for me

  1. File->Project Structure

  2. Select Project from left panel

  3. Now change your Gradle Version at right panel

Solution 26 - Android

I found a root cause of this problem for my case under Ubuntu 16.04. Both .gradle and project directories should have proper permissions. I've created this directories by myself and that's why they had more restricted permissions. I just let Android Studio to create both this directories bu itself and everything was working as expected.

Solution 27 - Android

None of the solutions here worked for me. For anyone who might run into my situation, here's what worked for me:

In addition to the steps here, I also

  1. Deleted ~/.gradle/daemon/[GRADLE_VERSION]
  2. Deleted ~/.gradle/wrapper/dists/gradle-[GRADLE_VERSION]-all
  3. Deleted [PROJECT_PATH]/.gradle

Restarted Android Studio

Solution 28 - Android

My problem was used the same Gradle file in Module Gradle and app Gradle module Gradle file was added with 'api' .

Solution 29 - Android

In my case, none of the previous answers worked for me. The solution was to delete the entire gradle folder (not the .gradle folder inside the project) and replaced it with a gradle folder backup, independenly where it's located in the operative system.

I had tried deleting only the cache folder but the problem persisted maybe because I was using a customized gradle folder provided from my job.

I do not recommend this solution in general but if none of the others works, then replace the complete gradle directory or reinstall could be a solution.

Solution 30 - Android

If this error occurs while you are trying to run an app on your mobile device via phone USB, make sure the compiled compileSdkVersion and buildToolsVersion are up to date, if they are, just uninstall the app in your phone and run the app again. If the error persists then go-to C:\Users\name.gradle\caches\5.6.4\javaCompile and deletes the javaCompile.lock file then runs the app again. Hope that solves your problem.

Solution 31 - Android

I just solved this problem by simply Cleaning the Project and then Rebuilding it.

Solution 32 - Android

A Simple Solution

In my case just change distribution URL to latest

Go to gradle-wrapper.properties and change distributionUrl to latest

distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip

And yet not solve this Error just do Clean Project Rebuild Project and Restart Android Studio.

Solution 33 - Android

It doesn't work none of above all.

  1. Close the project.
  2. Remove from project list
  3. Re-import the project again. (If you have a whole source file of a project, you should clean previous project and extract the project again)
  4. Open intellij and click open the project.
  5. Select the extracted folder/ project folder.

It is done.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaTToView Question on Stackoverflow
Solution 1 - AndroidRizView Answer on Stackoverflow
Solution 2 - AndroidAshish TikaryeView Answer on Stackoverflow
Solution 3 - AndroidAshishView Answer on Stackoverflow
Solution 4 - AndroidWarrockerView Answer on Stackoverflow
Solution 5 - AndroidsushildlhView Answer on Stackoverflow
Solution 6 - AndroidSUTHANSEEView Answer on Stackoverflow
Solution 7 - AndroidRazzView Answer on Stackoverflow
Solution 8 - AndroiddvaeyView Answer on Stackoverflow
Solution 9 - AndroidgMaleView Answer on Stackoverflow
Solution 10 - AndroidJakir HossainView Answer on Stackoverflow
Solution 11 - AndroidVandit GoelView Answer on Stackoverflow
Solution 12 - AndroidLettings MallView Answer on Stackoverflow
Solution 13 - AndroidSurbhi KartpayView Answer on Stackoverflow
Solution 14 - AndroidLeonView Answer on Stackoverflow
Solution 15 - AndroidSalem BairaView Answer on Stackoverflow
Solution 16 - AndroidAkeshwar JhaView Answer on Stackoverflow
Solution 17 - AndroidAllan_Aj5View Answer on Stackoverflow
Solution 18 - AndroidTheStormAfterTheCalmView Answer on Stackoverflow
Solution 19 - Androiduser6771720View Answer on Stackoverflow
Solution 20 - AndroidRohit AgarwalView Answer on Stackoverflow
Solution 21 - AndroidA.R.B.NView Answer on Stackoverflow
Solution 22 - AndroidC6SilverView Answer on Stackoverflow
Solution 23 - AndroidHamza_DeveloperView Answer on Stackoverflow
Solution 24 - AndroidKartikeya_MView Answer on Stackoverflow
Solution 25 - AndroidSudishresthaView Answer on Stackoverflow
Solution 26 - AndroidYazon2006View Answer on Stackoverflow
Solution 27 - AndroidNewton MuneneView Answer on Stackoverflow
Solution 28 - AndroidLibin ThomasView Answer on Stackoverflow
Solution 29 - AndroidjmoranView Answer on Stackoverflow
Solution 30 - AndroidRamin ArView Answer on Stackoverflow
Solution 31 - AndroidNitish kumarView Answer on Stackoverflow
Solution 32 - AndroidBhavin SolankiView Answer on Stackoverflow
Solution 33 - AndroidGünay GültekinView Answer on Stackoverflow