Build.gradle in project vs. build.gradle in app

I started a project in Android Studio using IntelliJ.

The project includes two files named build.gradle

. One is under the folder app

and one is under the main folder which is the name of my project for example MyProject


Why do you need two? What is the difference between the two build.gradle



source to share

1 answer

An Android Studio project consists of modules, libraries, manifest files, and Gradle build files.

Each project contains one top-level Gradle file . This file is called build.gradle and can be found in the top level directory.

This file usually contains a common configuration for all modules, common functions.


  //gradle-plugin for android
  buildscript {
    repositories {
        mavenCentral()  //or jcenter()

    dependencies {
        classpath ''        

  // common variables
  ext {
     compileSdkVersion = 19
     buildToolsVersion = "20.0.0"

  // a custom function
  def isReleaseBuild() {
     return version.contains("SNAPSHOT") == false

  //common config for all projects
  allprojects {
     version = VERSION_NAME

     repositories {


All modules have a specific build.gradle

. This file contains all information about this module (as the project can contain more modules) like config, build tyoes, info for signing your apk, dependencies ...


apply plugin: ''

android {
    //These lines use the constants declared in top file
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionName project.VERSION_NAME  //it uses a property declared in
        versionCode Integer.parseInt(project.VERSION_CODE) 

    // Info about signing
    signingConfigs {

    // Info about your build types
    buildTypes {
        if (isReleaseBuild()) {
            release {
                signingConfig signingConfigs.release

        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"

    // lint configuration
    lintOptions {
        abortOnError false

//Declare your dependencies  
dependencies {
    //Local library
    compile project(':Mylibrary')
    // Support Libraries
    compile ''
    // Picasso
    compile 'com.squareup.picasso:picasso:2.3.4'



You can find more information here:



All Articles