Fail InstallAndroidDependencies cleanly when ResolveAndroidTooling has no resolved SDK#11321
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/dotnet/android/sessions/ab9b627b-2492-407c-b80c-661d58857a34 Co-authored-by: davidnguyen-tech <87228593+davidnguyen-tech@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix silent failure in InstallAndroidDependencies for android-37.0
Fail May 11, 2026
InstallAndroidDependencies cleanly when ResolveAndroidTooling has no resolved SDK
Member
|
/review |
|
✅ Android PR Reviewer completed successfully! |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes InstallAndroidDependencies to fail cleanly when ResolveAndroidTooling runs without a resolved Android SDK, replacing a NullReferenceException-derived XARAT7001 with the proper XA5300 error.
Changes:
- In
ResolveAndroidTooling.RunTask, validateMonoAndroidHelper.AndroidSdkandAndroidSdkPathafter computingAndroidApiLevel, loggingXA5300and returningfalsewhen unavailable. - Replace
MonoAndroidHelper.AndroidSdkaccesses with the locally capturedandroidSdkvariable. - Add a task-level regression test that nulls out
MonoAndroidHelper.AndroidSdkand asserts deterministic failure withXA5300(and noXARAT7001).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs | Guards against null AndroidSdk/empty AndroidSdkPath before probing tooling paths and emits XA5300. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs | Adds NUnit test validating the new failure path while preserving AndroidApiLevel computation. |
There was a problem hiding this comment.
✅ LGTM — Clean, focused fix with good regression coverage.
Summary:
- The null guard correctly prevents the
NullReferenceException→XARAT7001cascade by checkingMonoAndroidHelper.AndroidSdkandAndroidSdkPathbefore dereferencing. - Intentionally places the guard after
AndroidApiLevelcomputation soInstallAndroidDependenciesstill gets the API level for dependency resolution — smart design. - Local
androidSdkvariable eliminates repeated static field access — good practice. - Formatting fix (
new [] {) aligns with Mono style. - Test properly isolates the scenario, verifies both positive (XA5300 logged) and negative (XARAT7001 not thrown) conditions, and restores global state in
finally.
CI: All checks passing ✅
Issue count: 0 ❌ · 0
Generated by Android PR Reviewer for issue #11321 · ● 2.5M
When JavaSdkPath is null (e.g. SDK not yet installed), Path.Combine throws ArgumentNullException. Add null checks in GetVersionFromTool and GetVersionFromFile to return gracefully instead of throwing. Added tests to verify both the UseJavaExeVersion=true and UseJavaExeVersion=false code paths handle null JavaSdkPath. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The NullJavaSdkPathDoesNotThrow test expects Execute() to fail when JavaSdkPath is null. Previously we only logged a debug message and returned null, which left Log.HasLoggedErrors=false and caused Execute() to return true. Log the existing XA5300_Java_SDK coded error in addition to the debug message so the task fails deterministically without throwing XAVJV7001. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers
approved these changes
May 20, 2026
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.
Fixes #11394
InstallAndroidDependenciescould exit successfully even when a required platform package was still missing. On a fresh SDK/JDK path,ResolveAndroidToolingandValidateJavaVersioncould dereference unresolved SDK state and throwNullReferenceException/ArgumentNullException(surfaced asXARAT7001/XAVJV7001), leaving dependency installation to continue as warnings instead of producing a hard failure.ResolveAndroidToolingMonoAndroidHelper.AndroidSdkandAndroidSdkPathbefore probing build-tools / cmdline-tools paths.XA5300Android SDK error and returnsfalseinstead of throwingXARAT7001from aNullReferenceException.ValidateJavaVersionGetVersionFromTool/GetVersionFromFilepreviously threwArgumentNullException(surfaced asXAVJV7001) whenJavaSdkPathwas null, becausePath.Combine (JavaSdkPath, ...)was called unguarded.GetVersionFromToolnow logsXA5300(Java SDK directory could not be found) and returnsnullsoExecute()fails deterministically.GetVersionFromFileonly falls back toPath.Combine (JavaSdkPath, "release")whenJavaSdkPathis set.Why this matters
InstallAndroidDependenciesnow gets a real task failure signal when SDK or JDK tooling resolution has not succeeded.platforms;android-37.0to surface only later asXA5207.Focused coverage
ResolveSdksTaskTests: regression test assertingResolveAndroidTooling:AndroidApiLevelfor dependency resolution,XA5300,XARAT7001.ValidateJavaVersionTests:NullJavaSdkPathDoesNotThrowandNullJavaSdkPathWithReleaseFileDoesNotThrowcover both theUseJavaExeVersion=trueandUseJavaExeVersion=falsecode paths and assertExecute()returnsfalsewithout emittingXAVJV7001.