Skip to content

Instantly share code, notes, and snippets.

@tuanchauict
Last active December 15, 2016 06:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuanchauict/a5e230074abab40311a185d2abae2dc7 to your computer and use it in GitHub Desktop.
Save tuanchauict/a5e230074abab40311a185d2abae2dc7 to your computer and use it in GitHub Desktop.
Build, install and run release build

Grab code then

apply from: 'lazy.gradle'
apply plugin: 'com.android.application'
android.applicationVariants.all { variant ->
def name = variant.name.capitalize()
def outputFile = variant.outputs.get(0).outputFile
def applicationId = variant.applicationId
task("clear$name") {
doLast{
def proc = "adb shell pm clear $applicationId".execute()
proc.waitFor()
}
}
task("remove$name") {
doLast{
def proc = "adb shell am start -a android.intent.action.DELETE -d package:$applicationId".execute()
proc.waitFor()
}
}
task("free$name") {
doLast {
def proc = "adb install -r ${outputFile.canonicalPath}".execute()
def sout = new StringBuilder(), serr = new StringBuilder()
proc.consumeProcessOutput(sout, serr)
proc.waitFor()
if (sout.toString().indexOf("INSTALL_FAILED_UPDATE_INCOMPATIBLE") >= 0) {
println("> Error: INSTALL_FAILED_UPDATE_INCOMPATIBLE")
println("> Remove old")
tasks.getByPath("remove$name").execute()
}
proc = "adb shell monkey -p $applicationId -c android.intent.category.LAUNCHER 1".execute()
proc.waitFor()
}
}
task("lazy$name") {
dependsOn "assemble$name"
dependsOn "free$name"
}
task("freshLazy$name"){
dependsOn "clear$name"
dependsOn "assemble$name"
dependsOn "free$name"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment