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

16,364

Solution 1

Delete the .gradle folder from user directory, not from the project.

C:\users\username\.gradle in windows
/home/username/.gradle in Linux 
/users/username/.gradle in Mac

Solution 2

Before you go deleting your entire general .gradle folder for android studio, please note the following implications and consequences.

  • It will cost as much as 3 -4 GB to re-download its content
  • The download could take days if you are not careful and the network is not super fast
  • For every old project you reopen, chances are some items are missing, therefore, the android studio will have to redownload missing content, god help you if you chose to take out your laptop at a random eatery without free internet and quickly get some work done.
  • The deletion process involves thousands of file, up to 119k, the operating system finding them will take forever and deletion will take even longer.

Here is a much better solution;

  • Close android studio completely
  • Using the file explorer of the operating system, in your app's project folder open the .gradle folder
  • Note the number(name) of the folder in it, such as (2.3 or 4.4 or 4.6 or 4.8)
  • Go to your general .gradle folder as described by @Gabriele Mariotti
  • open it and open the "caches" folder
  • Delete the folder with the same number as the second step
  • If you are paranoid like me you could also delete your project's .gradle file too (not necessary)

The file is not larger than 4 MB and it will not be re-downloaded but regenerated by android studio automatically, therefore the whole process should not take you 5 mins, costs no data, and all previous projects function as normal.

Solution 3

For linux users, Press ctrl+H to show hidden files inside home directory because .gradle directory is usually hidden and delete .gradle directory.

After that you might receive an error as "cannot lock build output" then remove the lock files in the gradle cache by executing something like this:

find ~/.gradle -type f -name "*.lock" -delete
Share:
16,364
lala
Author by

lala

Updated on June 25, 2022

Comments

  • lala
    lala about 2 years

    I updated my android studio into 2.3 then upon connecting my app to Firebase, it gave me an error:

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

    Do I need to go back to 2.2.3 or is there any way to fix this? I tried deleting .gradle file in my project but it still gave me an error.

  • busuu
    busuu almost 7 years
    AFTER 2 DAYS, FINALLY. THANK YOU.
  • djejaquino
    djejaquino over 6 years
    A power surge happened at the office during some Graddle dependency download. This solved the issue.
  • khwilo
    khwilo about 6 years
    A forced shutdown on my laptop raised this issue but I am glad this solution fixed it. Care to explain the resulting error? Thank you once again.
  • Zoe stands with Ukraine
    Zoe stands with Ukraine over 5 years
    Not necessarily. .gradle in a project just contains local caches. C:/Users/YourUsername/.gradle on the other hand contains the actual .jar caches, and that will require a lot of data. However, data isn't necessarily a problem for some people, because quite a lot of ISP's offer unlimited data. Time is another issue though.
  • EAM
    EAM over 5 years
    C:/Users/YourUsername/.gradle, this is the one I'm referring to, when I say don't delete lightly as instructed by @Gabriele Mariotti.
  • Waqar Vicky
    Waqar Vicky over 5 years
    i tried this solution but not working. I also do "Invalidate cache/Restart" but still error. Please help me.........