How to clear gradle cache?

2019-01-02 16:45发布

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 like 45 seconds.

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

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?

7条回答
无色无味的生活
2楼-- · 2019-01-02 17:41

Newest solution using gradle task

cleanBuildCache

available via android plugin for Gradle, revision 2.3.0 (February 2017)

Dependencies:

  1. Gradle 3.3 or higher.
  2. Build Tools 25.0.0 or higher.

more at:

https://developer.android.com/studio/build/build-cache.html#clear_the_build_cache

background

Build cache:

stores certain outputs that the Android plugin generates when building your project (such as unpackaged AARs and pre-dexed remote dependencies). Your clean builds are much faster while using the cache because the build system can simply reuse those cached files during subsequent builds, instead of recreating them. Projects using Android plugin 2.3.0 and higher use the build cache by default. To learn more, read Improve Build Speed with Build Cache.

Note: The cleanBuildCache task is not available if you disable the build cache.

usage:

windows

gradlew cleanBuildCache

linux / mac

gradle cleanBuildCache

Android Studio / IntelliJ

gradle tab (default on right) select and run the task or add it via the configuration window 

**gradle/gradlew are system specific files containing scripts - please see system info how to execute the script

  1. linux - https://www.cyberciti.biz/faq/howto-run-a-script-in-linux/
  2. windows - https://technet.microsoft.com/en-us/library/bb613481(v=vs.85).aspx
  3. mac https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/index.html
查看更多
登录 后发表回答