Amin Soheyli
Amin Soheyli

Reputation: 651

Gradle sync failed: Could not create parent directory for lock file

I checked out a git repository in android studio, but I'm in trouble with Gradle sync failed error.

When project wants to build, the android studio raise an error like as following:

Gradle sync failed: Could not create parent directory for lock file 
C:\Users\username\.gradle\wrapper\dists \gradle-4.10.1- 
all\455itskqi2qtf0v2sja68alqd\gradle-4.10.1-all.zip.lck

How can I solve this problem?

I appreciate you to solve this problem, thanks.

Upvotes: 9

Views: 32399

Answers (8)

Dan Guinn
Dan Guinn

Reputation: 1

For Linux Ubuntu users. I was able to fix by adjusting Android Studio Gradle Settings to point to /home/YOUR-USERNAME/.gradle/

Upvotes: 0

lhchuopp
lhchuopp

Reputation: 664

In my case, the Gradle user home field was changed to a non-default folder. However, that folder is NOT existed anymore (due to disk partition or something similar). Then, just remove the non-default folder to make Android Studio download Gradle stuff again to default folder - C:\Users\user-name\.gradle (or you can specify any other new valid folder I think). `Gradle user home config

Upvotes: 2

Azaruddin Shaikh
Azaruddin Shaikh

Reputation: 29

Delete '.gradle' file from the location C:\Users\your_computer_name.gradle After deletion the .gradle file close the Android studio. And open the Android studio Problem is fix

Upvotes: -1

nanosoft
nanosoft

Reputation: 3091

Same issue had troubled me long enough before I found this link for same issue in Intellij. After going the conversation, I found this is a permissions issue - which I should have figured out as the error clearly says "Failed to create parent directory".

I simply gave required permissions to the gradle directory and it worked. Similar to below(replace path_to_gradle to your actual path) :

chmod ugo+rwx <path_to_gradle>

Upvotes: 1

The Zetsumei
The Zetsumei

Reputation: 49

For anyone who still encountering this issue, I have just ran the Android Studio as administrator and it worked.

Upvotes: 3

Nikul Vadher
Nikul Vadher

Reputation: 139

Remove C:\Users\yourname.gradle

then close android studio and Start Android Studio with administrative permission.

it fixed in my case.

Upvotes: 4

Ranjan Kumar
Ranjan Kumar

Reputation: 1210

Run this following command:

gradlew clean
gradlew assembleDebug

If this does not work use following command.

gradlew --update-locks assembleDebug

Upvotes: 0

Amin Soheyli
Amin Soheyli

Reputation: 651

I found this answer:

  1. In the upper-right corner of android studio click on the Gradle tool, then right click on the your project name then click on the Refresh Gradle project as following:

Gradle --> Your project name --> Refresh Gradle project

  1. Then click on the Build -> Rebuild Project as following:

Build --> Rebuild Project

Upvotes: 1

Related Questions