Put your Android Studio on a diet

How to make a deep clean of your Android Studio & Gradle junk files to fix up the mess.

Florian Le Ficher
Sep 17, 2019 · 4 min read
Image for post
Image for post

Do you know that when you’re updating your Android Studio, Gradle or even dependencies, some old files are still present on your machine and can waste some disk free space?

On our laptops, disk space is limited and clearing those files will make you gain a lot of free space available. Having too many junk files may also slow down your machine and your builds!

In my case, I was also having strange build errors or gradle sync failures when it was working on my colleague’s machine.

It was time to do some deep cleaning and put our Android Studio on a diet by following some simple steps.

Image for post
Image for post
  1. Obviously, try to clean your project from android studio : “Build -> Clean Project”. This will clear your build folders.
  2. Clear the cache of Android Studio using “File -> Invalidate Caches / Restart” choose “Invalidate and restart option” and close Android Studio.
  3. Remove your .gradle directory from the root of your project. It contains some Gradle cache files.
  4. Delete also the .idea directory (make a backup before). It contains some project configuration files.
  5. Restart Android Studio.

Big project directories can weight around 500MB to 1GB.

Now let’s take a look at Gradle files. If none of the above suggestions fix your problem, try these:

Go to your ~/.gradle directory. This is the Gradle home directory, containing caches, daemons and wrappers files. This is a really huge one, mine was ~15GB.

Inside those directories, you’ll have sub-directories for each version of Gradle you’ve been using. So, the more projects you have with different Gradle versions, the more sub-directories you will have.
You can delete those 3 directories:

  • caches: Gradle cache files.
  • daemon: essentially logs files of Gradle daemons.
  • wrapper: different distributions of Gradle downloaded on you machine.
Image for post
Image for post
  1. Go to your Android home, usually ~/.android and clear build-cache and cache directories. There are few MB to free here (~100MB for me)
  2. In the ~/Library/{Preferences, Caches, Logs, Application Support} directories, you will find the Android Studio preferences files, settings and plugins. You can clear the directories of previous version of Android Studio (>1GB per version of AS). Starting with version 3.3, Android Studio will propose you to remove them after an update.
Image for post
Image for post
Android Studio 3.3 directories removal dialog
  • Android Studio 3.6 (still in preview) added an option to clear temporary files, which can free up some precious GB.
Image for post
Image for post
Android Studio 3.6 Canary 6 SDK manager

Android SDK cleaning

On Android Studio, check the SDK Manager and remove the following items:

  • Old SDKs you don’t use anymore. I guess you’ll not miss the Android 3.0 SDK files.
  • Remove the emulators you don’t use as they’re quite heavy (some GB).
  • I recommend to keep “Sources for Android xx” items as it will allow you to check the source code of the SDK from a previous version of Android & help you debugging.
  • On the SDK Tools tab, click on “Show Packages Details” and uncheck the old build-tools or NDK versions.
  • Delete unused emulators using the AVD.

You can gain easily 10GB with these steps.

There is some extra stuff you can clean too:

  • Your download directory: you may have downloaded a lot of GIFs, video, Android Studio binaries that you can remove.
  • Clear your local git branches that have been merged (don’t remove the ones that you still need!).
  • Delete all those photoshopped pictures of your colleagues ( ͡° ͜ʖ ͡°).
  • Clear your recycle bin.

That’s it ! You’ve gained some precious disk space on your machine and maybe fixed some weird issues with your Android Studio.

I don’t recommend to do a full clean everyday, you’ll waste time and your build time will be quite longer so you’ll be less productive. Take it only as a “spring cleaning” ritual.

I hope it helped you, and don’t forget to follow the Marie Kondo mantra and only keep things that spark joy.

Image for post
Image for post

Back Market Engineering

Creative engineers building a less wasteful world …

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store