Gradle Configuring Android Engineering

Source: Internet
Author: User

# Gradle Configure Android Project #


With the popularity of Android studio, Gradle also began to become popular in Android development. Here I share my grale script and my knowledge of gradle.


Basic structure of 1.Gradle




The gradle of the whole project is composed of Project Build.gradle, Seetings.gradle,gradle.properties,module Build.gradle.


# # 1.project Build.gradle # #
Projects Build.gradle is the resource required for all modules in the project. and configure the public resources in each module, such as version number, build tool, and other information

ext {
ApplicationID = "com.tracelijing.immediately"
Buildtoolsversion = "23.0.2"
Compilesdkversion = 23
Minsdkversion = 14
Targetsdkversion = 23
Versioncode = 1
Versionname = "1.0.0"
}


# # 2.settings.gradle: # #
This file is used to configure multiple modules, such as your project has two modules module-app,module-tlibrary, then you need to configure in this file, the format is as follows:

Include ': App ', ': Tlibrary '

# # 3.gradle.properties: # #
Gradle configuration file, such as can configure signature related information such as KeyStore location, password, Keyalias and so on.

# # 4.module.gradle: # #
The main thing is to configure the details of each sub-module, which we also mentioned in the root build.gradle to declare the common information of the child module, below we see how to use the Rootproject information in the module.

Android {
Compilesdkversion rootProject.ext.compileSdkVersion
Buildtoolsversion rootProject.ext.buildToolsVersion

Defaultconfig {
Minsdkversion rootProject.ext.minSdkVersion
Targetsdkversion rootProject.ext.targetSdkVersion
Versioncode RootProject.ext.versionCode
Versionname RootProject.ext.versionName
}
Buildtypes {
Release {
Minifyenabled false
Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro '
}
}



-The main difference between the module in Android is the following two

Android Application Module

Apply plugin: ' Com.android.application '

Android Project module

Apply plugin: ' Com.android.library '

-Engineering dependencies, JAR package management

Importing JAR Packages

' Compile files (' Libs/xxx.jar ') '

Import Project

' Compile project (': Module-a ') '

Import AAR

' Compile ' com.aaa.xxx:core:[email protected] '

Exclude dependencies
' Compile (group: ' xxx ', name: ' xxx ', version: ' xxx ') {
Exclude group: ' xxx ', module: ' xxx '//module corresponds to Artifactid} '


-Signature Management
Signature is a very sensitive thing, so we should keep it properly. Here we can develop the signature locally.
Define a Keystore.properties

Store_file=d\:\\code\\immediately.jks
store_password=123456
key_alias=123456
key_password=123456


Signingconfigs {
def properties props = new Properties ()
def propfile = new File (' Signing.properties ')
if (Propfile.canread ()) {
Props.load (New FileInputStream (Propfile))

Signingconfigs {
Release {
StoreFile file (props[' Store_file ')
Storepassword props[' Store_password ']
Keyalias props[' Key_alias ']
Keypassword props[' Key_password ']
}
Debug {
StoreFile file (props[' Store_file ')
Storepassword props[' Store_password ']
Keyalias props[' Key_alias ']
Keypassword props[' Key_password ']
}
}
} else {
Signingconfigs {
Debug {
println ' signing.properties not found '
}
}
}
}

-Output Management

Because the need to pack often, the APK file and the mapping file is not in the same place is more troublesome, so reproduce the definition of the APK file has been mapping file output path, so as to facilitate the management of resources

Android.applicationVariants.all {variant-
Variant.outputs.each {output-
def outputFile = Output.outputfile
def intofile = "D:\\immediaterelease"
if (outputFile! = null && outputFile.name.endsWith ('. apk ')) {
Here to modify the APK filename
def fileName = "Immediatel-${defaultconfig.versioncode}-${releasetime ()}.apk"
Output.outputfile = new File (Intofile, FileName)
}

if (Variant.getbuildtype (). isminifyenabled ()) {
Variant.assemble.doLast {
copy {
From Variant.mappingfile
Into Intofile
Rename {String FileName-
"Mapping-${defaultconfig.versioncode}-${releasetime ()}.txt"
}
}
}
}
}
}

# # Summary # #
This article only describes the basic structure of gradle and some basic configurations.
For more information, please refer to GitHub https://github.com/lijing01/immediately
Gradle can do a lot of things and then learn further.

Gradle Configuring Android Engineering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.