How To Clean A Project In Android Studio
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.
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.
Clear your project directory
- Obviously, try to clean your project from android studio : "Build -> Clean Project". This will clear your build folders.
- Clear the cache of Android Studio using "File -> Invalidate Caches / Restart" choose "Invalidate and restart option" and close Android Studio.
- Remove your .gradle directory from the root of your project. It contains some Gradle cache files.
- Delete also the .idea directory (make a backup before). It contains some project configuration files.
- Restart Android Studio.
Big project directories can weight around 500MB to 1GB.
Gradle cleaning
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.
Android Studio cleanup
- Go to your Android home, usually ~/.android and clear build-cache and cache directories. There are few MB to free here (~100MB for me)
- 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.
- Android Studio 3.6 (still in preview) added an option to clear temporary files, which can free up some precious GB.
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.
Extra cleaning
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.
How To Clean A Project In Android Studio
Source: https://medium.com/back-market-engineering/put-your-android-studio-on-a-diet-fa4d364acb05#:~:text=Clear%20your%20project%20directory,option%E2%80%9D%20and%20close%20Android%20Studio.
Posted by: trippcopievere.blogspot.com
0 Response to "How To Clean A Project In Android Studio"
Post a Comment