Commonly used gradle functions in androidStudio, androidstudio tutorial

Source: Internet
Author: User

Commonly used gradle functions in androidStudio, androidstudio tutorial

1. gradle uses the current version of svn.

def getSvnRevision() {    new ByteArrayOutputStream().withStream { os ->        def result = exec {            executable = 'svn'            args = ['info']            standardOutput = os        }        def outputAsString = os.toString()        def matchLastChangedRev = outputAsString =~ /Last Changed Rev: (\d+)/        ext.svnRev = "${matchLastChangedRev[0][1]}".toInteger()    }    return svnRev}

Example:

versionCode 1versionName "0.${versionCode}." + getSvnRevision()

 

Use git checkout's 6-bit short version information.

Task gitReversion {def cmd = "git rev-parse -- short HEAD"
// Git rev-list -- all | wc-l get the submitted def proc = cmd.exe cute () ext. revision = proc. text. trim ()}

Example:

versionCode 1versionName "0.${versionCode}." + gitReversion.revision

  

Gradle:

Task copyTaskWithPatterns (type: Copy) {from "$ {buildDir}/outputs/apk/" into "c:/apks /"

// Do not copy unsigned files. exclude {details-> details.file.name.endsWith('-unaligned.apk ') | details. file. name .endsWith('-unsigned.apk ')} include "**/*. apk "println" apk copied. $ {buildDir} "} build. doLast {tasks.copyTaskWithPatterns.exe cute ()}

Note that if you are lazy in writing, exclude is before include.

 

The following build file specifies the output file name.

BuildTypes {release {runProguard true proguardFiles getdefadefaproguardfile('proguard-android.txt '), 'proguard-rules. pro 'signingconfig signingConfigs. release} debug {runProguard false proguardFiles getdefadefaproguardfile('proguard-android.txt '), 'proguard-rules. pro' debuggable true jniDebugBuild true} applicationVariants. all {variant-> def file = variant. outputFile if (variant. buildType. name. equals ("release") {// judge the compiled type variant. outputFile = new File (String) file. parent, (String) (project. archivesBaseName + "-" + variant. mergedFlavor. versionName + ". apk ")} else {variant. outputFile = new File (String) file. parent, (String) (project. archivesBaseName + "-" + variant. mergedFlavor. versionName + ". apk "))}}}

  

 

In addition

Variant. baseName = {moduleName}-debug,
Project. archivesBaseName = {projectName}
Variant. name = {moduleName} Debug

 

For how to use gradle in android-studio, see: http://tools.android.com/tech-docs/new-build-system/user-guide

 

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.