Skip to content

Improve SDK detection and cmdline-tools remediation - #89

Merged
Redth merged 1 commit into
mainfrom
fix/sdk-cmdline-tools-detection
Feb 26, 2026
Merged

Redth merged 1 commit into
mainfrom
fix/sdk-cmdline-tools-detection

Conversation

@Redth

@Redth Redth commented Feb 26, 2026

Copy link
Copy Markdown
Owner

Why

Users reported crashes when running android sdk list and android sdk info against SDKs that have platform-tools, build-tools, and emulator installed but are missing cmdline-tools (which contains sdkmanager/avdmanager). Android Studio can create SDK installations in this state — it manages packages through its own internal mechanisms and doesn't always install cmdline-tools.

Fixes Redth/MAUI.Sherpa#38

What Changed

SdkComponentScanner (new)

Scans SDK directories by reading package.xml files to inventory installed components without requiring sdkmanager. Returns an SdkInventory with component details and helper properties (HasCmdlineTools, HasPlatformTools, HasBuildTools, etc.).

Graceful CLI degradation

  • sdk info now shows installed components via scanner and warns when cmdline-tools are missing — instead of crashing
  • sdk list falls back to scanner results when sdkmanager is unavailable
  • Both commands show an actionable remediation hint: android sdk download --home <path>

Library-level improvements

  • SdkManager.List() falls back to the scanner when sdkmanager is missing
  • SdkManager.Start() throws a typed SdkManagerToolNotFoundException with an actionable message instead of a generic InvalidOperationException
  • SdkLocator ranks discovered SDKs by completeness (prefers those with cmdline-tools) while preserving explicit --home priority

Fixed sdk download command

  • Removed the blocker that prevented running against existing SDK directories
  • Changed --force to only delete cmdline-tools/ subdirectory (previously it deleted the entire SDK directory!)
  • Added a check for already-installed cmdline-tools with a helpful message

How to Validate

Before (crash):

$ android sdk info --home /path/to/sdk-without-cmdline-tools
Unhandled exception. System.InvalidOperationException: ...

After (graceful):

$ android sdk info --home /path/to/sdk-without-cmdline-tools
⚠ cmdline-tools not found in SDK...
To install: android sdk download --home "/path/to/sdk"

Installed Components:
  emulator 36.3.10
  platform-tools 36.0.2
  build-tools;36.1.0 36.1.0
  platforms;android-36 2

Remediation:

$ android sdk download --home /path/to/sdk-without-cmdline-tools
# Downloads and installs cmdline-tools into the existing SDK safely

Tests

  • 7 new SdkComponentScanner tests (null/empty/single/multi component, cmdline-tools detection, invalid XML handling)
  • 4 new SdkManager not-installed tests (FindToolPath null, List fallback, correct details, exception type)
  • All existing tests continue to pass

When an Android SDK is missing cmdline-tools (e.g. installed by Android Studio
without them), the CLI commands would crash with NullReferenceException or
InvalidOperationException. This change adds graceful detection, fallback
inventory scanning, and a safe remediation path.

## Why

Users reported crashes when running `android sdk list` and `android sdk info`
against SDKs that had platform-tools, build-tools, and emulator installed but
were missing cmdline-tools (which contains sdkmanager/avdmanager). Android
Studio can create SDK installations in this state. See Redth/MAUI.Sherpa#38.

## What

### SdkComponentScanner (new)
- Scans SDK directories via package.xml files to inventory installed components
  without requiring sdkmanager
- Returns SdkInventory with component details and helper properties
  (HasCmdlineTools, HasPlatformTools, HasBuildTools, etc.)

### Graceful CLI degradation
- `sdk info` now shows installed components via scanner and warns when
  cmdline-tools are missing instead of crashing
- `sdk list` falls back to scanner results when sdkmanager unavailable
- Both commands show actionable remediation hint:
  `android sdk download --home <path>`

### Library-level improvements
- SdkManager.List() falls back to scanner when sdkmanager is missing
- SdkManager.Start() throws typed SdkManagerToolNotFoundException with
  actionable message instead of generic InvalidOperationException
- SdkLocator ranks discovered SDKs by completeness (prefers those with
  cmdline-tools) while preserving explicit --home priority

### Fixed sdk download command
- Removed blocker that prevented running against existing SDK directories
- Added check for already-installed cmdline-tools

### Tests
- 7 new SdkComponentScanner tests (null, empty, single/multi component,
  cmdline-tools detection, invalid XML handling)
- 4 new SdkManager not-installed tests (FindToolPath null, List fallback,
  correct details, exception type)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Test Results

  4 files    4 suites   30m 24s ⏱️
114 tests 111 ✅ 3 💤 0 ❌
228 runs  222 ✅ 6 💤 0 ❌

Results for commit 451c8a6.

@Redth
Redth merged commit a52e3e4 into main Feb 26, 2026
7 checks passed
@Redth
Redth deleted the fix/sdk-cmdline-tools-detection branch February 26, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android SDK/JDK Detection Issues

1 participant