Skip to content

Commit

Permalink
build: install to multiple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Jan 14, 2024
1 parent b17a8d2 commit e9184f5
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.gradle.configurationcache.extensions.capitalized
import java.io.ByteArrayOutputStream

plugins {
alias(libs.plugins.androidApplication)
Expand Down Expand Up @@ -153,12 +157,27 @@ dependencies {
afterEvaluate {
properties["debug_flavor"]?.toString()?.let { tasks.findByName("install${it.capitalized()}Debug") }?.doLast {
runCatching {
exec {
commandLine("adb", "shell", "am", "force-stop", properties["debug_package_name"])
val devices = ByteArrayOutputStream().also {
exec {
commandLine("adb", "devices")
standardOutput = it
}
}.toString().lines().drop(1).mapNotNull {
line -> line.split("\t").firstOrNull()?.takeIf { it.isNotEmpty() }
}
Thread.sleep(1000L)
exec {
commandLine("adb", "shell", "am", "start", properties["debug_package_name"])

runBlocking {
devices.forEach { device ->
launch {
exec {
commandLine("adb", "-s", device, "shell", "am", "force-stop", properties["debug_package_name"])
}
delay(500)
exec {
commandLine("adb", "-s", device, "shell", "am", "start", properties["debug_package_name"])
}
}
}
}
}
}
Expand Down

0 comments on commit e9184f5

Please sign in to comment.