Difference between build.gradle (Project) and build.gradle (Module)

I am trying to add an Android Asynchronous Http Client dependency to my project. Thus, there are two build.gradle files in the project.

enter image description here

According to my understanding, there are different dependencies:

  • One that is defined at the root level of build.gradle (Project: My-app)
  • One inside build.gradle built-in script (Project: My-app)
  • Another is build.gradle (Modules: application)

This question is about buildScript dependency repositories, explain a little about the first two types.

Also build.gradle (Project: My-app) says

// NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files 

So, I think the Android Asynchronous Http Client dependency code should be added to build.gradle (Module: app).

If someone can give a clear idea of ​​all these considerations for a better understanding, it would be great.

+51
android android-studio build.gradle
Feb 03 '15 at 9:54
source share
2 answers

build.gradle(Project:My-app)

A top-level assembly file in which you can add configuration parameters common to all subprojects / modules.

Each project contains a top-level gradle file . It usually contains common configs for all modules . Whatever is included in this top-level gradle , this will affect all modules .

Example:

 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.0.0-alpha3' //Maven plugin classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() maven { url "https://jitpack.io" } } } task clean(type: Delete) { delete rootProject.buildDir } 



build.gradle(Module:app)

Create a file for your specific module (where you add your dependencies, sign configs, build types, flavors, etc.)

All modules have a specific gradle file . Regardless of what is included in this gradle file, this will only affect the module that is included.

Example:

 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.hrskrs.gesturefun" minSdkVersion 10 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { zipAlignEnabled true minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable true zipAlignEnabled true minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':gesture-fun') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.jakewharton:butterknife:7.0.1' } 
+18
Feb 03 '15 at 10:09
source share

This is a bit confusing, because Android Studio by default shows both build.gradle files side by side (when using the Android view).

enter image description here

If you switch to the Project view, you will see the actual structure and where the different build.gradle files are build.gradle .

enter image description here

The build.gradle file (Project: MyApplication) is located in the root folder of the project, and its settings apply to each project module. The module is an isolated part of a larger project. In a multi-module project, these modules have their own jobs, but work together to form an entire project. Most Android projects have only one module, the application module.

The build.gradle file (Module: app) is located in the app folder. Its build settings apply only to the application module. If another module existed, it would also have its own build.gradle file. As an example, I created a library project with three modules: a library module, an application demo module, and another application module that I plan to use for testing. Each of them has its own build.gradle files, which I can configure.

enter image description here

In the base project, almost everything you need to change will be in the build.gradle file of the application file. You can remember this as follows:

You are creating an application, so go to the build.gradle file (Module: app).

Further reading

+9
Aug 30 '16 at 15:02
source share



All Articles