Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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"

The project iml file has a BUILD_FOLDER_PATH attribute. I haven't tried changing it myself yet, so not sure if it will work. The default value is $MODULE_DIR$/build.

Edit: I did a quick test and this did not work. Once changed, the project needs to reload because the iml file changed. Upon reload it reverts the build directory to default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top