Skip to content

Instantly share code, notes, and snippets.

@rozkminiacz
Last active April 28, 2023 16:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rozkminiacz/8efef5228659e1c6272e24c006b922cf to your computer and use it in GitHub Desktop.
Save rozkminiacz/8efef5228659e1c6272e24c006b922cf to your computer and use it in GitHub Desktop.
apply from: "$rootDir/run-app.gradle"
./gradlew installAndRunDebug
./gradlew installAndRunRelease
android.applicationVariants.all { variant ->
def taskName = "installAndRun${variant.name.capitalize()}"
tasks.register(taskName) {
def artifactPath = "${variant.outputs.first().outputFile}"
def packageName = variant.applicationId
doLast {
def installCommand = "adb install -r ${artifactPath}"
def installProcess = installCommand.execute()
installProcess.waitFor()
def installOutput = installProcess.text
println(installOutput)
if (installProcess.exitValue() != 0) {
throw new Exception("Failed to install app.")
}
def startCommand = "adb shell am start ${packageName}"
def startProcess = startCommand.execute()
startProcess.waitFor()
def startOutput = startProcess.text
println(startOutput)
if (startProcess.exitValue() != 0) {
throw new Exception("Failed to start app")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment