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?
Command:
rm -rf ~/.gradle/caches/
You can do it on Android Studio
https://www.jetbrains.com/idea/help/cleaning-system-cache.html
Update: above method will clear Android Studio cache, not Gradle cache. Gradle cache locates at
%USER_HOME%\.gradle/caches/
$HOME/.gradle/caches/
You can browse to these directory and manually delete it or run
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:
On Mac or Linux:
The gradle daemon also creates a many large text files of every single build log. They are stored here:
"X.X" is the gradle version in use, like "4.4", and "XXXX" are just random numbers, like "1234".
The total size can grow to several hundred MB in just a few months. There is no way to disable the logging, and the files are not automatically deleted and they do not really need to be retained.
But you can create a small gradle task to automatically delete them, and free up lots of disk space:
Add this to your
app/build.gradle
:To see which files are being deleted, you can see the debug output in Android Studio -> View -> Tool Windows -> Build. Then press "Toggle View" button on that window to show the text output.
Note that a Gradle Sync or any Gradle Build will trigger the file deletions.
A better way would be to automatically move the files to the Trash/Recycle Bin, or at least copy them to a Trash folder first. But I don't know how to do that.
Take care with gradle daemon, you have to stop it before clear and re-run gradle.
Stop first daemon:
Clean cache with:
Run again you compilation
You can safely delete the whole.gradle
folder located under project directory. It'll be recreated every time the tasks are run. The same is for.gradle
under home directory. It'll also be recreated as well, but the whole dependencies must be downloaded again - it's quite time-consuming.As I see in various places over the web gradle for android development is quite slow and people complain about it. No idea what's reason exactly - this is how it works.
I don't think that low performance is because of big folders. Actually they help it to be faster.
As @Bradford20000 pointed out in the comments, there might be a
gradle.properties
file as well as global gradle scripts located under$HOME/.gradle
. In such case special attention must be paid when deleting the content of this directory. The cache directory holds theGradle
build cache. So if you have any error about that you can delete that. It's on.gradle/caches
If you are interested in the entire cache of IntelliJ. Here you go.
You need not to do it manually, let the IntelliJ do it for you. Go to control panel and try to uninstall it. It prompts you the option to delete the cache, and other options as well. Think twice before you attempt it. It might create other problems, like other answers mentioned about this.