Search code examples
androidandroid-studiogradleandroid-gradle-pluginandroid-studio-2.0

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.


Solution

  • 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.