commit e9184f5244e29e1ae80967710ed4a7ecdaebf6c4
parent b17a8d245418d9352c0bfcdfb77390ecb890274b
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Sun, 14 Jan 2024 11:34:19 +0100
build: install to multiple devices
Diffstat:
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
@@ -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)
@@ -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"])
+ }
+ }
+ }
}
}
}