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

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

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.