Improve SDK detection and cmdline-tools remediation - #89
Merged
Merged
Conversation
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>
Test Results 4 files 4 suites 30m 24s ⏱️ Results for commit 451c8a6. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Users reported crashes when running
android sdk listandandroid sdk infoagainst SDKs that have platform-tools, build-tools, and emulator installed but are missingcmdline-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.xmlfiles to inventory installed components without requiring sdkmanager. Returns anSdkInventorywith component details and helper properties (HasCmdlineTools,HasPlatformTools,HasBuildTools, etc.).Graceful CLI degradation
sdk infonow shows installed components via scanner and warns when cmdline-tools are missing — instead of crashingsdk listfalls back to scanner results when sdkmanager is unavailableandroid sdk download --home <path>Library-level improvements
SdkManager.List()falls back to the scanner when sdkmanager is missingSdkManager.Start()throws a typedSdkManagerToolNotFoundExceptionwith an actionable message instead of a genericInvalidOperationExceptionSdkLocatorranks discovered SDKs by completeness (prefers those with cmdline-tools) while preserving explicit--homepriorityFixed
sdk downloadcommand--forceto only deletecmdline-tools/subdirectory (previously it deleted the entire SDK directory!)How to Validate
Before (crash):
After (graceful):
Remediation:
Tests
SdkComponentScannertests (null/empty/single/multi component, cmdline-tools detection, invalid XML handling)SdkManagernot-installed tests (FindToolPath null, List fallback, correct details, exception type)