Guo Xiaoxing
Weibo: Guo Xiaoxing's Sina Weibo
Email:[email protected]
Blog: http://blog.csdn.net/allenwells
Github:https://github.com/allenwell
Before introducing Gradle for Android scripting syntax, let's take a look at some of the common Gradle script files in the Android Studio project, so we'll have a general impression, and then we'll discuss the relevant syntax in detail.
In Android Studio, Gradle is comprised of a top-level profile and other module configuration files, as shown in:
Let's take a look at these files in turn.
gradle Top-level configuration files
//top-level build file where can add configuration options Common To all Sub-projects/modules.buildscript {repositories {/* repository Jcenter, or you can configure MO VEN */ Jcenter ()} dependencies {/* dependent gradle version */ CL Asspath ' com.android.tools.build:gradle:1.2.3 ' // Note:do not place your application dependencies here; They belong //in the individual module Build.gradle files }}allproject s {repositories {/* repository for all projects */ Jcenter ()}}
The content of this file mainly contains two aspects: one is the source of the declaration warehouse, here can see is the specified Jcenter (), the previous version is Mavencentral (), Jcenter can be understood as a new central remote warehouse, compatible with MAVEN Central warehouse, and better performance. Another is the version that declares Android Gradle plugin, the Android Studio 1.0 Official edition must require support for Gradle Plugin 1.0 version.
Global project configuration file
Settings.gradle
include‘:app‘
This file is the global project configuration file, which mainly declares the need to join the Gradle module. The above file is only added to the app module, if there are extra modules, follow the above format to continue to add.
Gradle Wrapper Properties File
Gradle-wrapper.properties
#Wed Apr 10 15:27:10 PDT 2013distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
This is a file located under the wrapper folder that declares the Gradle directory and download path and the version of Gradle used for the current project. These default paths are generally not changed, and this file specifies that the Gradle version is not the same as the common reason why the guide package is unsuccessful.
Gradle Module configuration file
Build.gradle
Apply plugin:' Com.android.application '//Statement is Android programAndroid {Compilesdkversion A//Compile the SDK versionBuildtoolsversion"22.0.1"version of//build toolsDefaultconfig {//default configurationApplicationID"Com.allenwells.myapplication"//Application package nameMinsdkversion the//Minimum API versionTargetsdkversion A//Compile API versionVersioncode1//Version numberVersionname"1.0"//Version name} buildtypes {//Build TypeRelease {//Official version configurationMinifyenabledfalse//whether to confuseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}//confuse the location of the configuration file}//Remove error from lint checklintoptions {Abortonerrorfalse} sourcesets {main {jnilibs.srcdirs =[' Libs ']}}}dependencies {//dependent configuration, compile all jar packages under the Libs directoryCompile Filetree (dir:' Libs ', include: [' *.jar ']) Compile' com.android.support:appcompat-v7:22.1.1 ' //Compile the Shimmerandroid module in the Extras directoryCompile Project (': Extras:shimmerandroid ')}
A few notes on the above documents:
- Apply plugin is the latest gradle version of the wording, the previous wording is the Apply plugin: ' Android '.
- Buildtoolsversion This requires you to install the version locally, many people import new third-party libraries, one of the reasons for the failure is that the build version is incorrect, this can be changed manually to your local version or Open SDK Manager to download the corresponding version.
- ApplicationID represents the app's package name, and is also the latest notation.
- Android 5.0 starts the default installation of jdk1.7 to compile.
- Minifyenabled is also the newest grammar, very early runproguard.
- Proguardfiles This section has two paragraphs, the previous part represents the system default Android program confusion file, the file already contains the basic confusion statement, eliminates many of our things, this file directory in
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Android Studio Discovery Road Series" Eight: Gradle Project building System (II): Gradle for Android scripting syntax