Sabuncu Sabuncu - 27 days ago 11
Android Question

Why are there two build.gradle files in an Android Studio project?

After having imported an Eclipse project into Android Studio, I see two


1 - <PROJECT_ROOT>\build.gradle
2 - <PROJECT_ROOT>\app\build.gradle

The first version is shorter, the second version contains definitions for
, etc.

What is the purpose behind having two separate files? Are there separate build tasks?

Answer Source

<PROJECT_ROOT>\app\build.gradle is specific for app module.

<PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules.

If you use another module in your project, as a local library you would have another build.gradle file: <PROJECT_ROOT>\module\build.gradle

For example in your top level file you can specify these common properties:

buildscript {
    repositories {

    dependencies {
        classpath ''

ext {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.1"

In your app\build.gradle

apply plugin: ''

repositories {

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion