From f0421ec7ad739d0340caf7960736317b201c1e59 Mon Sep 17 00:00:00 2001 From: Adam Seals Date: Fri, 5 Jun 2026 23:28:27 -0500 Subject: [PATCH] fixed windows adb not found issue --- lua/android/sdk/discovery.lua | 2 +- lua/tests/android/sdk/discovery_test.lua | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lua/android/sdk/discovery.lua b/lua/android/sdk/discovery.lua index 925b817..d13afe8 100644 --- a/lua/android/sdk/discovery.lua +++ b/lua/android/sdk/discovery.lua @@ -288,7 +288,7 @@ function M.new(opts) local config = opts and opts.config or nil local root = opts and opts.root or nil local cwd = opts and opts.cwd or nil - local os_name = opts and opts.os_name or nil + local os_name = opts and opts.os_name or vim.loop.os_uname().sysname local home = opts and opts.home or nil local discovery = {} diff --git a/lua/tests/android/sdk/discovery_test.lua b/lua/tests/android/sdk/discovery_test.lua index 27d0c52..0928ab5 100644 --- a/lua/tests/android/sdk/discovery_test.lua +++ b/lua/tests/android/sdk/discovery_test.lua @@ -153,6 +153,34 @@ local function locates_sdk_tools_on_windows() assert.eq(tools.adb, "C:/Sdk/platform-tools/adb.exe", "adb windows") end +local function auto_detects_windows_tool_extensions() + local original_uname = vim.loop.os_uname + vim.loop.os_uname = function() + return { sysname = "Windows_NT" } + end + + local store = require("android.state.store").new() + local discovery = require("android.sdk.discovery").new({ + env = { ANDROID_SDK_ROOT = "C:/Sdk" }, + exists = function(path) + local matches = { + ["C:/Sdk"] = true, + ["C:/Sdk/cmdline-tools/latest/bin/sdkmanager.bat"] = true, + ["C:/Sdk/cmdline-tools/latest/bin/avdmanager.bat"] = true, + ["C:/Sdk/emulator/emulator.exe"] = true, + ["C:/Sdk/platform-tools/adb.exe"] = true, + } + return matches[path] or false + end, + store = store, + }) + + local tools = discovery.tools() + assert.eq(tools.adb, "C:/Sdk/platform-tools/adb.exe", "auto-detected adb windows") + + vim.loop.os_uname = original_uname +end + local function falls_back_to_tools_bin() local store = require("android.state.store").new() local discovery = require("android.sdk.discovery").new({ @@ -236,6 +264,7 @@ function M.run() uses_default_sdk_candidates() locates_sdk_tools() locates_sdk_tools_on_windows() + auto_detects_windows_tool_extensions() falls_back_to_cmdline_tools_bin() falls_back_to_tools_bin() locates_aapt2_from_build_tools()