@@ -226,11 +226,14 @@ internal class AdbLogcatService(
226226 // ── ADB helpers ────────────────────────────────────────────────────────
227227
228228 private fun resolveAdbPath (): String? {
229+ val isWindows = System .getProperty(" os.name" ).lowercase().contains(" win" )
230+ val adbName = if (isWindows) " adb.exe" else " adb"
231+
229232 // 1. Try ANDROID_HOME / ANDROID_SDK_ROOT environment variables
230233 val sdkRoot = System .getenv(" ANDROID_HOME" )
231234 ? : System .getenv(" ANDROID_SDK_ROOT" )
232235 if (sdkRoot != null ) {
233- val adb = File (sdkRoot, " platform-tools${File .separator} adb " )
236+ val adb = File (sdkRoot, " platform-tools${File .separator}$adbName " )
234237 if (adb.exists() && adb.canExecute()) {
235238 return adb.absolutePath
236239 }
@@ -244,7 +247,7 @@ internal class AdbLogcatService(
244247 localProps.inputStream().use { props.load(it) }
245248 val sdkDir = props.getProperty(" sdk.dir" )
246249 if (sdkDir != null ) {
247- val adb = File (sdkDir, " platform-tools${File .separator} adb " )
250+ val adb = File (sdkDir, " platform-tools${File .separator}$adbName " )
248251 if (adb.exists() && adb.canExecute()) {
249252 return adb.absolutePath
250253 }
@@ -254,13 +257,20 @@ internal class AdbLogcatService(
254257 // Ignore and try next fallback
255258 }
256259
257- // 3. Try common macOS / Linux SDK locations
258- val commonPaths = listOf (
259- " ${System .getProperty(" user.home" )} /Library/Android/sdk/platform-tools/adb" ,
260- " ${System .getProperty(" user.home" )} /Android/Sdk/platform-tools/adb" ,
261- " /opt/homebrew/bin/adb" ,
262- " /usr/local/bin/adb" ,
263- )
260+ // 3. Try common SDK locations
261+ val userHome = System .getProperty(" user.home" )
262+ val commonPaths = if (isWindows) {
263+ listOf (
264+ " $userHome \\ AppData\\ Local\\ Android\\ Sdk\\ platform-tools\\ adb.exe" ,
265+ )
266+ } else {
267+ listOf (
268+ " $userHome /Library/Android/sdk/platform-tools/adb" ,
269+ " $userHome /Android/Sdk/platform-tools/adb" ,
270+ " /opt/homebrew/bin/adb" ,
271+ " /usr/local/bin/adb" ,
272+ )
273+ }
264274 for (path in commonPaths) {
265275 val adb = File (path)
266276 if (adb.exists() && adb.canExecute()) {
@@ -269,11 +279,12 @@ internal class AdbLogcatService(
269279 }
270280
271281 // 4. Fallback: adb on PATH
282+ val whichCommand = if (isWindows) arrayOf(" cmd" , " /c" , " where" , " adb" ) else arrayOf(" which" , " adb" )
272283 return try {
273- val proc = ProcessBuilder (" which " , " adb " )
284+ val proc = ProcessBuilder (* whichCommand )
274285 .redirectErrorStream(true )
275286 .start()
276- val path = proc.inputStream.bufferedReader().readText().trim()
287+ val path = proc.inputStream.bufferedReader().readText().trim().lines().first()
277288 proc.waitFor()
278289 if (path.isNotEmpty() && File (path).exists()) path else null
279290 } catch (_: Exception ) {
0 commit comments