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