Change gradle build directory in android studio?

2019-01-22 14:05发布

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?

3条回答
祖国的老花朵
2楼-- · 2019-01-22 14:41

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

查看更多
Animai°情兽
3楼-- · 2019-01-22 14:42

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.

查看更多
成全新的幸福
4楼-- · 2019-01-22 15:05

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"
查看更多
登录 后发表回答