Magnus
Magnus

Reputation: 18738

Gradle cache directory location in Android Studio 2

For every Android project I create, there is a .gradle folder in the root of the project. As I understand it, this only contains cache files used by Gradle, and can be recreated by Android Studio?

I'm wondering if there is a way to make Android Studio create these cache directories in another location, say /Temp/GradleCaches/<projectname>/.gradle?

I'm currently doing a course in Android programming, and those cache directories become quite huge when it's time to upload the projects. So instead of having to delete the directory I'd just like to have it created outside the project location.

Upvotes: 1

Views: 10130

Answers (3)

MojAmiri
MojAmiri

Reputation: 526

In Android Studio 3 (Gradle 3+) and Windows, It's located in the directory:

WINDOWS_DRIVE:\Users\YOUR_USER.gradle\caches

Note: DO NOT DELETE THE WHOLE FOLDER. Just search for your specific library and delete that one.

If you have some libraries that you want to reload from their repo, then you should delete files here. The cache here is also used by lint to inform you about new versions of library, and reloading the library.

This was the problem I had: I uploaded a new version (.aar file) to Artifactory(repo) by mistake but when I deleted it, gradle still was notifying me in my project about the new version.

Upvotes: 2

Magnus
Magnus

Reputation: 18738

I couldn't really get the solution proposed by Björn Kautler to work, and in any case it would mean that the projects I hand in to the examinator would point to a (most probably) invalid directory on their system.

Instead I simply created a symlink named .gradle in my project directory, which points to /Temp/GradleBuilds/cache/<project-name>/.gradle. That gets the cache directory out of the project path.

The next problem is still that when using OSx "Compress <folder-name>..." to zip a directory, it will include the symlink as-is, i.e. pointing to a (most probably) invalid directory on the recipients system. So in order to exclude the .gradle directory, I created an OSx service using Automator, which uses the command line utility zip to compress the folder, excluding the .gradle directory:

enter image description here

Activating it under System preferences -> Keyboard -> Shortcuts -> Services -> Files and folders makes it appear in the right click menu in Finder (possibly in the Services submenu if you have a lot of services).

So to wrap up, the .gradle cache directory is moved out of the project directory structure, and can easily be excluded when using the new service to compress the directory folder.

Upvotes: 0

Vampire
Vampire

Reputation: 38639

Just start gradle with the option --project-cache-dir path/to/where/you/want/it

Upvotes: 0

Related Questions