Error:Unexpected lock protocol found in lock file. Expected 3, found 0
AndroidGradleAndroid Gradle-PluginAndroid 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.
- In you project open
gradle-wrapper.properties
file. Which is located in Gradle Script in Android structure. As shown in below image.
- In that file check
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
. Here gradle version is 4.6.
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.
- 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.
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.
- Open the Project pane, if not open already.
- Select the Project view (not Android) from the drop-down menu
- The first folder (in red colour) will be .gradle, Right Click > Delete.
- Build the project again.
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
-
Get into the
.gradle
folder in the root of the project. -
There, you might see a couple of versions. Pick the gradle version that you're using in the porject.
-
cd into
taskArtifacts
folder. -
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
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:
- Selected "File\Close Project" and the project closed.
- The opening screen to create a new project came up.
- I deleted the project from the list just to have it not show in the list.
- Created a new project with a slightly different name.
- 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.
- First I removed application from Android Studio Launcher List.
- Second I deleted all the content from .gradle (FOLDER FROM USER DIRECTORY).
- Third I import the project again (after sync i got the error again).
- 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
- Go to File -> Project structure
- Select Project
- 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
-
File->Project Structure
-
Select Project from left panel
-
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
- Deleted
~/.gradle/daemon/[GRADLE_VERSION]
- Deleted
~/.gradle/wrapper/dists/gradle-[GRADLE_VERSION]-all
- 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.
- Close the project.
- Remove from project list
- 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)
- Open intellij and click open the project.
- Select the extracted folder/ project folder.
It is done.