Change gradle build directory in android studio?

20,425

Solution 1

in root build.gradle

allprojects {
    buildDir = "/path/to/build/${rootProject.name}/${project.name}"
}

See also Gradle global build directory

and docs https://gradle.org/docs/current/userguide/writing_build_scripts.html

Solution 2

You can pass the "buildDir" property to the gradlew.bat (I'd assume you can do this in the Linux version as well but I haven't tested it)

Example:

gradlew.bat assembleRelease -PbuildDir="C:\BuildFolder"
Share:
20,425
Pablo Jomer
Author by

Pablo Jomer

I'm a software engineer currently stationed in Linköping, Sweden where I work at a small startup constructing automatic software for 3D-reconstruction of buildings. I enjoy programming, board games, math, hiking, art and hanging out with my girlfriend (soon to be wife).

Updated on July 15, 2022

Comments

  • Pablo Jomer
    Pablo Jomer almost 2 years

    I just installed Android Studio and I am just learning to build using Gradle. However, with the default project setup, my builds are located in the project directory and I would like to have them placed elsewhere (preferably outside of the project directory). Is it possible to achieve this? Where do I make a change and what change do I make?

  • Pablo Jomer
    Pablo Jomer over 9 years
    I never used this answer. So I can't verify that it is indeed correct.
  • xyz
    xyz almost 9 years
    Works like a charm. Had do shift my build folder out of eCryptfs directory!
  • lorenzo-s
    lorenzo-s about 8 years
    Yeeeee! I can finally work in our company's Dropbox, thank you!
  • Jorge Aguilar
    Jorge Aguilar over 7 years
    @AlexeyKuznetsov I tried this and something similar by jsut applying it to subprojects, but, i only get some things move out of the default directory, i still see the R files and the intermediates (like exploded-aar, and things like that) on the default directory, which are the things that i wanted to move out in the first place, any idea what can i do? i've tried everything i've found online as far now
  • P i
    P i almost 6 years
    Note that this answer is telling you something _NOT_ to do! That .iml is automatically generated.
  • Zingam
    Zingam about 4 years
    This will cause: Duplicate content roots detected for test directories.