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

The question:

After having imported an Eclipse project into Android Studio, I see two build.gradle files:

1 - <PROJECT_ROOT>build.gradle
2 - <PROJECT_ROOT>appbuild.gradle

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

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

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

<PROJECT_ROOT>appbuild.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:

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

buildscript {
    repositories {

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

ext {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.1"

In your appbuild.gradle

apply plugin: 'com.android.application'

repositories {

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

Method 2

From the official documentation:

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.

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

Project Build File

<PROJECT_ROOT>build.gradle or the Project Build File is for the entire project, so it will be used for global project configurations.
A typical Project Build File contains the following:

  • buildscript which defines:
    • repositories and
    • dependencies
  • Gradle Plugin version

By default, the project-level Gradle file uses buildscript to define the Gradle repositories and dependencies. This allows different projects to use different Gradle versions. Supported repositories include JCenter, Maven Central, or Ivy. This example declares that the build script uses the JCenter repository and a classpath dependency artifact that contains the Android plugin for Gradle version 1.0.1.

Module Build File

<PROJECT_ROOT>appbuild.gradle or the Module Build File is for a specific module so it will be used for specific module level configurations.
A Module Build File contains the following:

  • android settings
  • compileSdkVersion
  • buildToolsVersion
  • defaultConfig and productFlavors
    • manifest properties such as applicationId, minSdkVersion, targetSdkVersion, and test information
  • buildTypes
    • build properties such as debuggable, ProGuard enabling, debug signing, version name suffix and testinformation
  • dependencies

You can read the official documentation here:

Projects and modules build settings

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment