Introduction to the. gradle file
In an Android Studio project, there will be multiple. gradle files. Where there is a Build.gradle file and a settings.gradle file in the project directory; a build.gradle file exists for each module.
A basic explanation of Gradle
Settings.gradle
//Top-level build file where can add configuration options common to all sub-projects/modules.Buildscript {//To set the code to drive the build processrepositories {Jcenter ()//declaration using the MAVEN repository. In the old version, here is Mavencentral (). //Mavencentral (): Indicates dependency is obtained from the Central Maven 2 warehouse. //Jcenter (): Indicates dependency is obtained from Bintary's Jcenter Maven repository. //**mavenlocal () * *: Indicates dependency is obtained from the local Maven repository. } dependencies {//declared using the Android Studio gradle plugin version. General upgrade as or import from you need to modify the following Gradle version when you build the project in//eclipse. Classpath' com.android.tools.build:gradle:1.2.2 ' //Note:do not place your application dependencies here; they belong //In the individual module Build.gradle files}}allprojects {//Set up the build process for each module. In this example, each module is set to use a //MAVEN warehouse dependent. repositories {Jcenter ()}}
The default project directory contains the contents of the Settings.gradle file as above. It is possible that by default, the Settings.gradle file under the project directory does not exist and you can create it yourself.
? Include ': App ': Indicates that there is a module named app under current project. :
If you need to introduce a module that is not under the project's root directory
Can be set as follows
include‘:app2‘project(‘:app2‘new File(‘path/to/app2‘)
Next, we'll talk about the Build.gradle file in module
Apply plugin:' Com.android.application 'Android {Compilesdkversion ABuildtoolsversion"22.0.1"Defaultconfig {ApplicationID"Com.hzchou.myapplication"Minsdkversion -Targetsdkversion AVersioncode1Versionname"1.0"} buildtypes {release {minifyenabledfalseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}}dependencies {Compile Filetree (dir:' Libs ', include: [' *.jar ']) Compile' com.android.support:appcompat-v7:22.2.0 '}
? Apply plugin: ' Com.android.application ':
Represents the use of the Com.android.application plug-in. That is to say, this is an Android application module. Com.android.library says this is an Android library module.
? Android:
Configure the parameters required for all Android build processes.
? Compilesdkversion:
The SDK version used for compiling.
? Buildtoolsversion:
The version of the tool used to compile the Gradle project.
? Defaultconfig:
Android Project default settings.
1. ApplicationID: Application package name.
2. Minsdkversion: Minimum supported Android version.
3. Targetsdkversion: Target version. It should actually be the Android version of the test machine under the test environment.
4. Versioncode: Version number.
5. Versionname: Version name.
? Buildtypes:
The compilation type. There are two default: Release and Debug. We can add our own buildtypes here, which we can see in the Build variants panel
? Minifyenabled:
Whether to use confusion. In the old version for Runproguard, the new version of the name, because the new version supports the removal of unused resource files, and Runproguard this name is not appropriate.
? Proguardfiles:
Using a confusing file, you can use multiple confusing files. In this example, the use of theSDKThe Proguard-android.txt file in the current module directory and the Proguard-rules.pro file.
? Dependencies
The dependency used to formulate the reference.
1. Compile Filetree (dir: ' Libs ', include: [' *.jar ']):
References all. jar files in the Libs folder under the current module directory.
2. Compile ' com.android.support:appcompat-v7:21.0.3 ':
Reference 21.0.3 version of APPCOMPAT-V7 (the commonly used v7* Library project).
Android developer tools for Android Studio----Gradle