Why use Gradle?
Gradle is a relatively advanced build system and a good build tool that allows customized build logic through plug-ins
The following are the main reasons why Android Studio chooses Gradle:
p>
Use Domain Specific Language to describe and process build logic. (hereinafter referred to as DSL)
Based on Groovy. DSL can mix various declaration elements and use code to manipulate these DSL elements to achieve logical customization.
Supports existing Maven or Ivy warehouse infrastructure
It is very flexible and allows the use of best practices without forcing you to follow its principles.
Other plug-ins can expose their own DSL and API for Gradle build files to use.
Allows IDE integration and is a good API tool
Need to prepare:
Gradle 1.6 or 1.7
SDK with Build Tools 17.0 .0 (released 5/16/2013)
Basic Project
In the root directory of the Gradle project, there is a file called build.gradle, which describes the overall project Build the foundation.
Build file
The most basic java program, its build.gradle file has just one sentence:
apply plugin: 'java'
< p>The most basic Android project, its build.gradle is as follows:buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}< /p>
apply plugin: 'android'
android {
compileSdkVersion 17
}
Let’s analyze it step by step Let’s take a look at the contents of the above three parts.
buildscript{...} configures the code that drives the build. It declares that it will take a classpath dependency from the Maven central warehouse, which is the Android plugin for Gradle v0.5.6
apply plugin specifies that the plugin used is android, just like in the previous java program, the plugin used is java
android{...} configures all the parameters of the android build, which is the Android DSL entry point.
By default, only the target compilation environment is necessary, which is the attribute compileSdkVersion. This is similar to the previous target property in project.properties.
It is worth noting that if you write apply plugin:java instead of apply plugin:android in the Android project, the build will fail.