Skip to content

[AndroidSdk] Prepare SDK discovery for task environments - #13536

Merged
simonrozsival merged 6 commits into
mainfrom
jonathanpeppers-sdk-discovery-preparation
Nov 13, 2026
Merged

simonrozsival merged 6 commits into
mainfrom
jonathanpeppers-sdk-discovery-preparation

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

SDK/JDK fallback discovery reads process environment values, and Windows discovery can change JAVA_HOME and PATH. This prevents ResolveSdks from safely using separate task environments.

Pass a complete environment snapshot through discovery, executable searches, and Java probes while preserving fallback order and missing-tool diagnostics. Add only AndroidSdkInfo.CreateWithEnvironment and JdkInfo.FindJdk; existing public signatures and optional defaults remain unchanged. ResolveSdks uses these entry points and the existing task-aware reference-version lookup. This is preparation only: MT remains disabled, and task-relative path handling is separate work.

Tests cover distinct environment values, SDK/JDK fallback, Java probe values, and XA5300 errors. No device tests or shared adb teardown ran. This overlaps the discovery/process helpers in #12988; whichever merges second needs adaptation.

Validation used this worktree's rebuilt outputs:

  • dotnet-local.cmd build Microsoft.Android.slnx -t:BuildDotNet -c Debug -m -p:AndroidToolchainDirectory=D:\android-toolchain -p:AndroidSdkDirectory=D:\android-toolchain\sdk -p:AndroidNdkDirectory=D:\android-toolchain\ndk -p:JavaSdkDirectory=D:\android-toolchain\jdk-21 -nr:false: passed, 86 warnings, 0 errors before the final API simplification. Changed library and task outputs were rebuilt afterward.
  • bin\Debug\dotnet\dotnet.exe build src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=11.0 -p:_AndroidTreatWarningsAsErrors=true -v:minimal -nr:false: passed, 0 warnings/errors; also passed with DotNetTargetFrameworkVersion=10.0. Both include netstandard2.0.
  • bin\Debug\dotnet\dotnet.exe test tests\Xamarin.Android.Tools.AndroidSdk-Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=11.0 -p:_AndroidTreatWarningsAsErrors=true -v:minimal --filter "FullyQualifiedName~JdkInfoTests|FullyQualifiedName~AndroidSdkInfoTests" -nr:false: 41 passed, 6 existing platform skips; same result with DotNetTargetFrameworkVersion=10.0.
  • bin\Debug\dotnet\dotnet.exe build src\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj -p:BuildProjectReferences=false -v:minimal -nr:false: passed, existing CS2002 warning only.
  • bin\Debug\dotnet\dotnet.exe build src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj -p:BuildProjectReferences=false -v:minimal -nr:false: passed, 0 warnings/errors.
  • bin\Debug\dotnet\dotnet.exe test bin\TestDebug\net11.0\Xamarin.Android.Build.Tests.dll --filter FullyQualifiedName~ResolveSdksTaskTests: 37 passed.
  • A consumer compiled against the original library ran unchanged against the revised DLL, including original constructor/method bindings and optional-parameter metadata checks. Recompiling the same source also passed.

The final alignment commit contains whitespace changes only. Strict MT builds are not claimed by this preparation.

jonathanpeppers and others added 5 commits November 10, 2026 15:54
Preserve existing discovery entry points and fallback order while passing task-specific environment snapshots through SDK/JDK lookup and Java probes. Keep ResolveSdks MT support disabled.

Co-authored-by: Copilot App <[email protected]>
Keep environment state on the existing JdkLocations type instead of threading it through each provider. Reuse existing test setup and remove unnecessary internal forwarding overloads.

Co-authored-by: Copilot App <[email protected]>
Keep original CLR entry points as forwarding overloads and put optional defaults only on the longest overload. Record the optional metadata changes explicitly in unshipped API files.

Co-authored-by: Copilot App <[email protected]>
Keep environment constructors and enumeration internal. Expose only SDK creation and JDK selection, reuse the JDK selection implementation, and restore all original public signatures and optional defaults.

Co-authored-by: Copilot App <[email protected]>
Align new field declarations, local variables, and assignment groups with the existing discovery code style.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 21:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Tool discovery can miss installed tools because Windows environment lookups depend on dictionary casing and Unix fallbacks ignore the supplied HOME.

2 open issues
What changed in this PR

Prepares SDK/JDK discovery for task-specific environments in .NET for Android while preserving existing public signatures. This does not enable multithreaded task execution or change task-relative path handling.

Changes:

  • Threads supplied environments through discovery, executable searches, and Java probes without changing the Windows process environment.
  • Adds AndroidSdkInfo.CreateWithEnvironment and JdkInfo.FindJdk, and integrates them into ResolveSdks.
  • Expands tests for environment-dependent discovery, fallback behavior, and XA5300 diagnostics.
File Description
tests/​Xamarin.Android.Tools.AndroidSdk-Tests/​JdkInfoTests.cs Tests environment-based JDK discovery and Java probes.
tests/​Xamarin.Android.Tools.AndroidSdk-Tests/​AndroidSdkInfoTests.cs Tests supplied environments and process-environment preservation.
src/​Xamarin.Android.Tools.AndroidSdk/​Sdks/​AndroidSdkWindows.cs Passes environments through Windows discovery and avoids process mutation.
src/​Xamarin.Android.Tools.AndroidSdk/​Sdks/​AndroidSdkUnix.cs Uses supplied environments for PATH discovery.
src/​Xamarin.Android.Tools.AndroidSdk/​Sdks/​AndroidSdkBase.cs Carries environments through shared discovery and validation.
src/​Xamarin.Android.Tools.AndroidSdk/​PublicAPI/​netstandard2.0/​PublicAPI.Unshipped.txt Records the two new public entry points.
src/​Xamarin.Android.Tools.AndroidSdk/​PublicAPI/​net11.0/​PublicAPI.Unshipped.txt Records the two new public entry points.
src/​Xamarin.Android.Tools.AndroidSdk/​PublicAPI/​net10.0/​PublicAPI.Unshipped.txt Records the two new public entry points.
src/​Xamarin.Android.Tools.AndroidSdk/​ProcessUtils.cs Adds environment-aware variable and executable lookup.
src/​Xamarin.Android.Tools.AndroidSdk/​OS.cs Passes environments into registry executable validation.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​XAPrepareJdkLocations.cs Moves toolchain discovery into the environment-carrying instance.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​VSAndroidJdkLocations.cs Passes environments through Visual Studio JDK discovery.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​OracleJdkLocations.cs Passes environments through Oracle JDK discovery.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​MicrosoftOpenJdkLocations.cs Makes Microsoft OpenJDK discovery instance-based.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​MicrosoftDistJdkLocations.cs Makes legacy Microsoft JDK discovery instance-based.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​JdkLocations.Windows.cs Uses supplied environments in Windows JDK lookups.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​JdkLocations.MacOS.cs Carries environments into macOS JDK construction.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​JdkLocations.cs Stores the environment shared by JDK locators.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​EclipseAdoptiumJdkLocations.cs Makes Adoptium discovery instance-based.
src/​Xamarin.Android.Tools.AndroidSdk/​Jdks/​AzulJdkLocations.cs Makes Azul discovery instance-based.
src/​Xamarin.Android.Tools.AndroidSdk/​JdkInfo.cs Adds FindJdk and environment-aware Java probing.
src/​Xamarin.Android.Tools.AndroidSdk/​AndroidSdkInfo.cs Adds environment-aware SDK construction.
src/​Xamarin.Android.Build.Tasks/​Utilities/​MonoAndroidHelper.Nullable.cs Delegates existing JDK selection to FindJdk.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​ResolveSdksTaskTests.cs Tests task environments and missing-tool errors; skips shared ADB teardown.
src/​Xamarin.Android.Build.Tasks/​Tasks/​ResolveSdksTask.cs Supplies the task environment to SDK/JDK and reference-version discovery.

Review effort: Balanced

Use Windows case-insensitive environment lookup without requiring a dictionary comparer. Resolve Unix SDK/JDK user paths and preferences from the supplied HOME, retaining null-snapshot and Windows preference behavior.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival

Copy link
Copy Markdown
Member

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13536

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — no blocking code findings. 0 errors, 0 warnings, 1 non-blocking inline suggestion.

Reviewed all 25 changed files and the relevant discovery/process call paths. The implementation preserves existing public signatures and fallback ordering, propagates the supplied environment into executable lookup and Java probes, and avoids Windows process-environment mutation on the snapshot path. The Windows case-insensitive lookup and Unix HOME fixes address the earlier review findings. Keeping MT enablement and task-relative path handling outside this preparation is consistent with the stated scope.

CI/validation: All 40 head-commit GitHub checks report success, including the aggregate dotnet-android check for Azure build 1678542. Direct Azure build/timeline verification was unavailable because the CLI queries failed. Attempted the focused JdkInfoTests/AndroidSdkInfoTests run with dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0 -v:minimal --filter 'FullyQualifiedName~JdkInfoTests|FullyQualifiedName~AndroidSdkInfoTests' -nr:false; .NET failed during NuGet named-mutex initialization before tests could run, so no local test pass is claimed.

Generated by Android PR Reviewer for #13536 · copilot · gpt61 · 53.5 AIC · ⌖ 4.31 AIC · ⊞ 20.2K
Comment /review to run again

Assert.IsNotNull (jdk);
Assert.AreEqual (root, jdk.HomePath);
Assert.AreEqual ($"${variable}", jdk.Locator);
Assert.IsTrue (jdk.GetJavaSettingsPropertyValue ("java.version", out var version));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 💡 Testing — Consider adding a case that keeps two discovered JdkInfo instances alive with different environment dictionaries and DISCOVERY_JAVA_VERSION values, then reads their Java properties concurrently. These parameterized cases exercise one snapshot at a time; interleaving discovery and the deferred Java probes would directly protect the separate-task-environment invariant without enabling MT on ResolveSdks yet.

{Rule: Test concurrent calls and environment isolation}

@simonrozsival
simonrozsival merged commit 198786d into main Nov 13, 2026
40 checks passed
@simonrozsival
simonrozsival deleted the jonathanpeppers-sdk-discovery-preparation branch November 13, 2026 13:29
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.

3 participants