Last active
June 6, 2023 19:07
-
-
Save erikghonyan/7159b01dec46166cc61d79bfa553f157 to your computer and use it in GitHub Desktop.
Installs and Runs the Android app from Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
androidComponents { | |
val adbPath = sdkComponents.adb.get().asFile.absolutePath | |
onVariants { variant -> | |
val capitalizedVariantName = variant.name.replaceFirstChar(Char::titlecase) | |
val applicationId = variant.applicationId.get() | |
tasks.register("run${capitalizedVariantName}") { | |
group = "run" | |
description = "Installs and Launches the $capitalizedVariantName build" | |
dependsOn("install${capitalizedVariantName}") | |
dependsOn("launch${capitalizedVariantName}") | |
} | |
tasks.register<Exec>("launch${capitalizedVariantName}") { | |
group = "run" | |
description = "Launches the $capitalizedVariantName build" | |
mustRunAfter("install${capitalizedVariantName}") | |
doFirst { | |
println("Launching $applicationId") | |
println("execute: ${commandLine.joinToString(" ")}") | |
} | |
commandLine = listOf( | |
adbPath, | |
"shell", "am", "start", | |
"-p", applicationId, | |
"-a", "android.intent.action.MAIN", | |
"-c", "android.intent.category.LAUNCHER", | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment