function PLUGIN:Available(ctx)
local http = require("http")
local env = require("env")
local base_url = env.ANDROID_SDK_MIRROR_URL or "https://dl.google.com/android/repository"
local metadata_url = base_url .. "/repository2-3.xml"
local resp = http.get({ url = metadata_url })
if resp.status_code ~= 200 then
error("Failed to fetch Android SDK metadata: HTTP " .. resp.status_code)
end
local versions = {}
local seen = {}
for path_attr in resp.body:gmatch('remotePackage%s+path="([^"]+)"') do
local version = path_attr:match("^cmdline%-tools;(.+)$")
if version and version ~= "latest" and not seen[version] then
seen[version] = true
table.insert(versions, {
version = version,
note = "",
})
end
end
table.sort(versions, function(a, b)
return a.version < b.version
end)
return versions
end