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