在将 Android Studio 升级到1.3之后,我不能再编译我的项目了。我正在接收 Unexpected lock protocol found in lock file. Expected 3, found 0.。我已经尝试删除我的 .gradle文件夹,但这并不能解决问题。还有什么我能做的吗?
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.
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:
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
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 ..
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.
-
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:
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
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.
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.
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.
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!
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.
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:
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.
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.