I'm just getting use to Gradle and Android Studio. I notice that Android Studio projects can have multiple build.gradle files. There is one located in the project's root folder and there's a second one located in the project's app folder. Can someone explain what the purpose of having these two are? When I do a build in AS, are both used or just one of them (and if only one of them, which one)?
Yes. You can have multiple build files in one project. The only thing you can't do, of course, is have multiple files named build. gradle in the same folder.
Android Studio projects contain a top-level project Gradle build file that allows you to add the configuration options common to all application modules in the project. Each application module also has its own build. gradle file for build settings specific to that module.
Each module has its own build file, so every Android Studio project contains two kinds of Gradle build files.
The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.
If your project contains multiple modules, you may use the root (project-level) build.gradle file to keep configuration common to all modules. E.g. you may put common dependencies there.
Default top-level build.gradle for Android Studio has "allprojects" block in the top-level build.gradle that adds "jcenter" repository to every module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With