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" | |
} | |
} |