Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple build.gradle files in Android Studio

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)?

like image 974
Johann Avatar asked Oct 24 '14 15:10

Johann


People also ask

Can you have multiple build Gradle files?

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.

Why are there multiple build Gradle files?

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.

How many types of Gradle build files do we have in Android?

Each module has its own build file, so every Android Studio project contains two kinds of Gradle build files.

Where is the build Gradle file in Android Studio?

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.


1 Answers

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.

like image 76
Eugene Avatar answered Sep 17 '22 17:09

Eugene