Droids are taking a bath

Android Studio Spring Cleaning

Cedric Ferry

--

When is the last time you’ve cleaned your Android Studio? Spending months or even years with Android Studio, you surely accumulated tons of cached data, break points and other SDKs. In this article, I’m going to take you through the steps to get a nice and clean Android Studio. No broom required, I promise.

Cache

First of all let’s starts with the basics, Invalidate Caches. On top of cleaning Android Studio, this feature can also help you to fix a project that has difficulties compiling.

Head to File Menu and select Invalidate Caches / Restart

Select “Invalidate and Restart" and Android Studio will take care of everything. It will take a bit longer than usual to restart as the IDE will have to recreate the necessary cache.

Break points

Ticking the red dot here and there, and then forgetting about it? Surely, one day, while debugging something else, your debugger will stop to an unexpected step. It’s time to clean up your Break Points.

Open the Break Point Manager, via the menu Run and View Break Points.

Break Point Manager

You can then select the Break Points that aren’t relevant to you, or just remove everything to start fresh.

Bonus Tip

You can also start to be organised and use Break Point Groups

Select a Break Point, right click, select Move to group, Create new…

Create a new group
your break point is now in a group

Gradle

Gradle is downloading tons of packages and keep them in cache. After a while it can really be huge, we are talking about gigabytes here. Most of the time outdated packages are still kept while never used. We can clean all of that and save disk space.

First of all quit Android Studio. Make sure nothing else is using gradle while performing the below operations.

The cache

You can clear only the cache and it will save you a few gigs. Next time you build, gradle will download the package required.

rm -rf ~/.gradle/cache

All-in, nothing to loose

If you look closely, you will see that gradle is a pig and keep so many things, for instance look at ~/.gradle/wrapper it keeps everything for every single version of gradle. You can get rid of this without fear, it will be re-created when required. The following command removes the entire gradle data.

Warning: if you’ve global gradle preferences they might be store in this folder, such as ~/.gradle/gradle.properties so you might want to save this one.

rm -rf ~/.gradle

It saved me nearly 4Gb!

Expect a slow start next time, AS+Gradle will need to download everything necessary for your App to build.

Note: if you use gradle for other things outside AS, be very careful with removing .gradle

Emulators

If like me, you like to try your App with the latest and older OS, to make sure your App works perfectly, you surely have a few OS Images taking Gigs that might not be useful anymore. Let’s review them.

Head to Tools Menu > AVD Manager or icon ( phone 📞 with an Android 🤖)

This view gives you a clear idea about how much space each emulator is taking. Review and remove the unnecessary (like older beta versions) or duplicates.

click the pointing down arrow ⬇️ then select Delete

FYI: The emulators are stored ~/.android/avd you can access quickly via “Show on Disk” in the menu above.

Android SDKs

When developing for Android platform for years, you surely have a lot of SDK Platforms, and SDK Tools. After having removed a few emulators, you should have an idea of what you can remove here.

Head to the Tools > SDK Manager, or the SDK Manager Icon (grey box with blue arrow pointing down 📦⇩)

SDK Platforms and System Images

Let’s start with the SDK Platforms, if your compileSdkVersion is recent, you should be able to remove a few. Make sure you tick “Show Package Details” so you can inspect and do a tailored clean up.

Some packages like the Sources might not be useful anymore.

In addition, look at System Images as each of them account for 1 to 3Gb. They are used for your emulators, so if you removed some in the previous step, you might not need this bit anymore. It can also be the right time to download the lastest.

FYI: The System Images are stored here ~/Library/Android/sdk/system-images

untick the old package you do not require anymore

SDK Tools

If you are using a recent version of buildToolsVersion. You should be building with fairly recent SDK Build Tools, you can then remove any older. It is the right time to also get the latest version. If for some reasons you need an older one for a legacy project, Android Studio will prompt you to install it.

List of SDK Build-Tools

Feeling Lighter and Tidier?

If you have followed some of the steps described in this article, you and your computer surely feels better. A few gigabytes saved and a cleaner, more organised Android Studio.

Thanks for reading this article, I hope it has been useful to you, as usual hit the clap button has much as you save space on your computer! 👏

If you are into Android Development, checkout ADN: Android Developer News to stay up-to-date with the latest tech in Android field.

--

--