Common functions of Gradle in Androidstudio

Source: Internet
Author: User

1. Gradle uses the current version of SVN information.

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}

Examples of Use:

Versioncode 1versionName "0.${versioncode}." + Getsvnrevision ()

Use Git checkout for 6-bit short version information.

Task Gitreversion {    def cmd = "git rev-parse--short HEAD"
Git rev-list--all | Wc-l Get commit secondary def proc = Cmd.execute () ext.revision = Proc.text.trim ()}

Examples of Use:

Versioncode 1versionName "0.${versioncode}." + Gitreversion.revision

  

Gradle Copy files:

Task Copytaskwithpatterns (type:copy) {from    "${builddir}/outputs/apk/" to    "c:/apks/"

Unsigned files are not copied. Exclude {details-details.file.name.endsWith ('-unaligned.apk ') | | details.file.name . EndsWith ('- unsigned.apk ')} include "**/*.apk" println "apk copied. ${builddir} "}build.dolast { tasks.copyTaskWithPatterns.execute ()}

The note is that if lazy writing, exclude before the include.

The following build file specifies the file name of the output.

    Buildtypes {release {runproguard true proguardfiles getdefaultproguardfile (' Proguard-an Droid.txt '), ' Proguard-rules.pro ' signingconfig signingconfigs.release} debug {RUNPR Oguard false Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro ' Debu Ggable true Jnidebugbuild true} Applicationvariants.all {variant, def file = va Riant.outputfile if (variant.buildType.name.equals ("release")) {//To determine the type of compilation Variant.outputfile = n EW File (String) file.parent, (String) (Project.archivesbasename + "-" + VA                Riant.mergedFlavor.versionName + ". apk")}else{ Variant.outputfile = new File (string) file.parent, (String) (Project.archi Vesbasename + "-" + variAnt.mergedFlavor.versionName + ". apk"))}}} 

  

Other than that

Variant.basename = {Modulename}-debug,
Project.archivesbasename ={projectname}
Variant.name={modulename}debug

about how Gradle are used in Android-studio. See also: Http://tools.android.com/tech-docs/new-build-system/user-guide

Common functions of Gradle in Androidstudio

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.