Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ayushhgoyal/1cdecde0298189e43846 to your computer and use it in GitHub Desktop.
Save ayushhgoyal/1cdecde0298189e43846 to your computer and use it in GitHub Desktop.
Using this snippet in gradle will copy the apk to dropbox folder (you can change the path wherever you want it to export) and renames it with current svn revision of the project. Add this in "buildTypes" - parallel to "dependencies".
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
// println()
def result
new ByteArrayOutputStream().withStream { os ->
result = exec {
// executable = 'svnversion'
// args = '| cut -d : -f 2 | cut -d M -f 1'
commandLine 'svn_script.sh'
// args '| cut -d : -f 2 | cut -d M -f 1'
standardOutput = os
}
result = os.toString().trim()
}
def app_name = project.rootDir.name.replace(" ", "_")
def final_apk_name = app_name + "_rev" + result + ".apk"
println("Final build: " + final_apk_name)
println("outputFile.parent: " + outputFile.parent)
def dropbox_path = "/home/ayush/Dropbox/AutomaticBuilds/" + app_name
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// def fileName = outputFile.name.replace('app-debug.apk', final_apk_name)
// output.outputFile = new File(dropbox_path, fileName)
// }
// now lets copy it to somewhere else
def originApkFile = output.outputFile;
def renameApkFile = originApkFile.name.replace('app-debug.apk', final_apk_name)
copy {
from "$originApkFile"
into "$dropbox_path"
rename("$originApkFile.name", "$renameApkFile")
}
// now delete original apk
// project.delete "$renameApkFile"
//
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment