How to clear gradle cache?

David T. picture David T. · Apr 12, 2014 · Viewed 568.9k times · Source

I'm trying to use Android Studio, and the first time I boot it up, it takes like 45 MINUTES to compile... If I don't quit the application, it is okay - each subsequent compilation/running the app will take around 45 seconds.

I've tried to check some of my caches: there's a .gradle/caches folder in my home directory, and it's contains 123 MB.

There's also a .gradle folder in my project folder... one of the taskArtifacts was like 200 MB. I'm scared to just randomly nuke them both. What parts of the folders are safe to delete?

Is there a better explanation for why my Android Studio is taking forever to run the gradle assemble task upon first time loading the application?

Do I also have to clear the intellij cache too?

Answer

Bao Le picture Bao Le · May 26, 2015

Gradle cache locates at

  • On Windows: %USER_HOME%\.gradle/caches/
  • On Mac/Unix: ~/.gradle/caches/

You can browse to these directory and manually delete it or run

rm -rf $HOME/.gradle/caches/

on Unix system. Run this command will also force to download dependencies.

Update 2: Clear the Android build cache of current project

Note: Android Studio's File | Invalidate Caches/Restart doesn't clear the Android build cache, so you'll have to clean it separately.

On Windows:

gradlew cleanBuildCache

On Mac or Linux:

./gradlew cleanBuildCache