Repository navigation
[release/11.0.1xx] [Build.Tasks] Remove shared Android SDK discovery state (#13145) - #13744
Open
jonathanpeppers wants to merge 2 commits into
Open
jonathanpeppers wants to merge 2 commits into
jonathanpeppers wants to merge 2 commits into
Conversation
2 of 3 tasks
Base automatically changed from
backport/pr-13133-to-release/11.0.1xx
to
release/11.0.1xx
November 24, 2026 14:21
…state (#13145) ## Why **The primary motivation is correctness under multithreaded MSBuild execution: remove mutable static SDK discovery state.** `MonoAndroidHelper.AndroidSdk` is a static field shared by task executions that use the same loaded task assembly in an MSBuild process. It is not scoped to a project or task invocation. Concurrent task executions can overwrite that field while another execution is reading it. For example, one project's `ResolveSdks` can install SDK A in the field, another project's `ResolveSdks` can replace it with SDK B, and the first project's SDK outputs or downstream tool/platform lookups can then come from SDK B. An explicit SDK directory on the consuming task does not prevent this when the lookup reads the static object instead. Keep the discovery object local to each `ResolveSdks` execution and make downstream queries use their own resolved SDK paths. This removes the shared SDK-discovery race rather than serializing task execution with a lock. Static state is process-local; this is not a claim that separate MSBuild worker processes share the field, nor that all Android tasks become thread-safe. `SupportedVersions` remains mutable static state and is intentionally deferred to a separate change. No build-time speedup is claimed, and there is no linked issue. ## Scope 13 related files, based directly on main at `0c3ac2489aaff9543ee1cb419e9da5ce1fdcf9f2`: - Remove only `MonoAndroidHelper.AndroidSdk` and `RefreshAndroidSdk`; retain `SupportedVersions`, `RefreshSupportedVersions`, all their consumers, and existing legacy API behavior. This removes one discovery-state hazard, not all task thread-safety hazards. - Add explicit-path `AndroidSdkInfo` overloads for build tools, command-line tools, and platform lookup. Existing instance methods share the same implementation; update the netstandard2.0/net10.0/net11.0 public API baselines. Preserve preferred-version ordering, stable/preview ordering, minor-version restrictions, preview fallback, and API 37 `.0` fallback. - Construct a local `AndroidSdkInfo` in `ResolveSdks` with coded logging. Preserve JDK validation inputs and NDK discovery fallbacks; emit absolute SDK/JDK/NDK/command-line-tools paths. - Use explicit SDK paths in tooling, manifest optional-library lookup, platform-JAR lookup, and jar2xml. Pass the resolved `_AndroidSdkDirectory` to the existing `GetJavaPlatformJar` input. - Cover SDK-path independence without JDK discovery, null arguments, ordering, platform fallbacks, missing-path coded errors, absolute outputs, and NDK fallback. No API metadata cache, static supported-version removal, nested-build forwarding/skipping, new public MSBuild properties, or performance claim is included. Co-authored-by: Copilot App <[email protected]> (cherry picked from commit bcdef48)
jonathanpeppers
force-pushed
the
jonathanpeppers-backport-13145-sdk-discovery
branch
from
November 24, 2026 14:21
4fecccb to
56dc892
Compare
jonathanpeppers
marked this pull request as ready for review
November 24, 2026 14:21
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Removing MonoAndroidHelper.AndroidSdk leaves references in two compiled test files, causing the full test suite build to fail with CS0117.
1 open issue
What changed in this PR
Backports #13145 to release/11.0.1xx, removing shared Android SDK discovery state so concurrent MSBuild task executions use their own resolved SDK paths. Shared supported-version state remains unchanged.
Changes:
- Keep SDK discovery local to
ResolveSdksand pass explicit paths to downstream consumers. - Add explicit-path SDK lookup APIs and update all three public API baselines.
- Extend regression tests for SDK isolation, lookup ordering, platform fallbacks, diagnostics, and absolute paths.
| File | Description |
|---|---|
tests/Xamarin.Android.Tools.AndroidSdk-Tests/AndroidSdkInfoTests.cs |
Tests explicit-path lookup isolation, ordering, and fallbacks. |
src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt |
Records three new lookup overloads. |
src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net11.0/PublicAPI.Unshipped.txt |
Records three new lookup overloads. |
src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net10.0/PublicAPI.Unshipped.txt |
Records three new lookup overloads. |
src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs |
Adds explicit-path APIs sharing existing lookup logic. |
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets |
Passes the resolved SDK directory to platform-JAR lookup. |
src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.Nullable.cs |
Removes shared SDK initialization. |
src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs |
Removes the SDK field and uses explicit paths for JAR lookup. |
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs |
Adds task-level path isolation and error-handling coverage. |
src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs |
Uses local discovery, coded logging, and absolute output paths. |
src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs |
Resolves tools from the supplied SDK path. |
src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs |
Resolves optional libraries from the supplied SDK path. |
src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs |
Uses the supplied SDK path for platform-JAR references. |
Review effort: Balanced
…ignments #13145 removed MonoAndroidHelper.AndroidSdk. On main, #13073 had already removed these two test assignments, but release/11.0.1xx still has them, so Xamarin.Android.Build.Tests fails with CS0117. Remove the dead assignments and the unused local. Co-authored-by: Copilot App <[email protected]>
3 tasks done
7 tasks
This branch has not been deployed
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.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
5961c980a43e8be188a70ff6bde3961b7441dd05↑ Review fix removes the only 2 remaining
MonoAndroidHelper.AndroidSdkreferences (dead test assignments); grep finds no others.↑ PublicAPI conflicts only add the 3 lines that #13145 adds.
↑ Xamarin.Android.Tools.AndroidSdk-Tests pass locally (net10.0).
↓ Xamarin.Android.Build.Tasks and its tests were not built locally; CI must validate them.
Backport of #13145.
Originally stacked on #13743 (backport of #13133), which is now merged; the base is now
release/11.0.1xx.Why
MonoAndroidHelper.AndroidSdkis mutable static state that task executions in the same MSBuild process share. ConcurrentResolveSdksexecutions can replace the field while another execution reads it, so one project can get SDK paths from a different project. This change keeps theAndroidSdkInfoobject local to eachResolveSdksexecution and makes downstream lookups use the explicit resolved SDK paths. See #13145 for the full description.Conflict resolution
git cherry-pick -x bcdef489af9daa431e5d8f41b16b218432fb907fconflicted only in:src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net10.0/PublicAPI.Unshipped.txtsrc/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net11.0/PublicAPI.Unshipped.txtsrc/Xamarin.Android.Tools.AndroidSdk/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txtThe conflict context on
mainincludes aDiscoverInstallationPathsline that does not exist onrelease/11.0.1xx. I kept the release lines and added only the 3 lines that #13145 adds (GetBuildToolsPaths,GetCommandLineToolsPaths,TryGetPlatformDirectoryFromApiLevel). All other files auto-merged, and their changed lines are identical to #13145.Release-only fix
On
main, #13073 (not in release) already removed two test assignments toMonoAndroidHelper.AndroidSdk. Onrelease/11.0.1xxthey still exist, soXamarin.Android.Build.Testsfailed with CS0117 after this backport. A second commit removes these dead assignments inNdkUtilTests.csandEnvironmentHelper.cs(and the now-unusedsdkDirlocal). No code reads the field, so test behavior does not change.Validation
dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0: passed (429 passed, 0 failed, 19 skipped).git grep -n "MonoAndroidHelper.AndroidSdk\b": only a comment inNdkTools.csremains (also present onmain).Xamarin.Android.Build.Tests(ResolveSdksTaskTests), and device tests. CI runs these.Pull Request
title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include: