Error in building project in Android Studio

22.3k views Asked by At

Freshly Installed Android Studio and started new android project. When tried to run it. Got this error from Gradle

Error:Could not open initscript class cache for initialization script 'C:\Users\Dexter\AppData\Local\Temp\asLocalRepo10.gradle' (C:\Users\Dexter\.gradle\caches\2.2.1\scripts\asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv\InitScript\initscript).
java.io.FileNotFoundException: C:\Users\Dexter\.gradle\caches\2.2.1\scripts\asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv\InitScript\initscript\cache.properties (The system cannot find the file specified)

I have tried to rebuild the project and also tried to delete .gradle folder but nothing worked.

10

There are 10 answers

2
Sagito On BEST ANSWER

I'm having the same problem and deleting just the cache.properties.lock is not enough.

The solution, as pointed before, is deleting the cache.properties.lock file, but not only in the folder pointed by Android Studio. I needed to remove every lock file inside .gradle\caches\VERSION.

So, I created a small .bat file with this:

del /s cache.properties.lock

Add this file to .gradle\caches\VERSION\ and run it. My Android Studio stopped complaining afterwards.

Hope it helps!

1
A.S On

go to location

".gradle\caches\2.0\scripts\build_7l4t45nbnsvdcl79ol8u0beli4\ProjectScript"

delete cache.properties.lock file

0
Christopher Rucinski On

Error Message

Error:Could not open initscript class cache for initialization script 
    'C:\Users\Dexter\AppData\Local\Temp\asLocalRepo10.gradle' 
    (C:\Users\Dexter\.gradle\caches\2.2.1\scripts\asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv
    \InitScript\initscript)
java.io.FileNotFoundException: C:\Users\Dexter\.gradle\caches\2.2.1\scripts\
    asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv\InitScript\initscript\cache.properties 
    (The system cannot find the file specified)`

The most important parts of this error message are

- Could not open initscript class cache
- asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv

So

  • Let _XXX_ = asLocalRepo10_d10e66d3o7exs19wwq4uj2zhv
  • Let _USER_ = Dexter
  • Let _GRADLE_ = 2.2.1

Solution

Delete C:\Users\_USER_\.gradle\caches\_GRADLE_\scripts\_XXX_\InitScript\initscript\cache.properties.lock

Does this not work?

Then you have to find out the root solution. This is probably due to a corrupt IDE. Try installing another copy of Android Studio on your system.

Note: You can have multiple copies of Android Studio on your system. Here is the latest Preview. If you check the notes on the page, you can see what you need to do to install a new version on AS.

Let us know if this works...if not, we can try to elimate other possible issues

0
SKP On

File -> Invalidate Cache / Restart worked for me.

0
SAURABH_12 On

For Me Issue get resolved by giving permission

  1. For window C:\Users Right click on Users >> Click on Security Tab >> Add Group and username there as for example SYSTEm, your comany mail id

  2. For Linux

provide 777 permission for .android and .gradle folder by using sudo chmod 777 -R .android/ sudo chmod 777 -R .gradle/

1
anuragsinhame On

I am also getting the same error.
So what I did is this that I cleared the Temp folder (If you don't know where it is then just hit Window+R and enter %temp% OR you can type %temp% in address bar too in File Explorer).
Now again run the project, it should run fine.
I don't know the permanent solution but what I am telling it works for me. If anyone do know the permanent fix then please share that.

0
Anand Kumar Jha On

In my case I have deleted .gradle folder and clean the project on re run the project was working fine.

enter image description here

0
VPaul On

In my case, it was the roaming profile issue. Gradle Sync failed every time I switched networks from work to home. Although I was able to access the network drives by connecting with VPN, still it used to give this error. I had to move the Gradle Service Directory Path to a different location that wasn't dependent on the network.

You can do this in AS 1.4 by going to File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Service Directory Path. Screen shot below:

enter image description here

You can also add GRADLE_USER_HOME environment variable with the same value of the location for making it a default for every project (http://blog.james-carr.org/2011/05/04/setting-gradle-cache-to-a-common-location/). You may refer to the following page for more info on moving Android related stuff to different locations: http://www.littlecpu.com/android-studio-c-drive

0
Prajun Adhikary On

I had similar issues. For me the solution was simply to delete all files inside the folder C:\Users\Dexter.gradle\caches\2.2.1\scripts\ Also i removed VCS configuration from android studio. No need to install new Android Studio to fix the issue.

0
Sadeq Shajary On

I have same problem. just restart your Gradle and then clean your project. i hope this help