From 9a889a14af3f6b6ea773623dde1e31189841fed1 Mon Sep 17 00:00:00 2001 From: Sergii Pechenizkyi Date: Wed, 6 Mar 2019 21:54:36 +0100 Subject: [PATCH] Fallback to ANDROID_SDK_ROOT if ANDROID_HOME is not defined --- .../main/kotlin/com/gojuno/commander/android/Adb.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt b/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt index 56eaa9c..ad6b492 100644 --- a/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt +++ b/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt @@ -11,7 +11,15 @@ import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit.MINUTES import java.util.concurrent.TimeUnit.SECONDS -val androidHome: String by lazy { requireNotNull(System.getenv("ANDROID_HOME")) { "Please specify ANDROID_HOME env variable" } } +val androidHome: String by lazy { + // Resolution order is from https://developer.android.com/studio/command-line/variables#envar + val androidHome = System.getenv("ANDROID_HOME") + if (androidHome != null) { + return@lazy androidHome + } + val androidSdkRoot = System.getenv("ANDROID_SDK_ROOT") + requireNotNull(androidSdkRoot) { "Please specify ANDROID_SDK_ROOT env variable" } +} val adb: String by lazy { "$androidHome${File.pathSeparator}platform-tools${File.pathSeparator}adb" } private val buildTools: String? by lazy { File(androidHome, "build-tools")