Repository navigation
[mt msbuild] Remove shared Android SDK discovery state - #13145
Conversation
Keep Android SDK discovery local to ResolveSdks instead of storing a mutable AndroidSdkInfo in MonoAndroidHelper. Query tool and platform paths using each consumer's resolved SDK directory, and normalize SDK, JDK, NDK and command-line tool outputs for task output transport. Preserve SupportedVersions and RefreshSupportedVersions, discovery fallbacks, tool ordering and platform API fallback behavior. Cover explicit path isolation, missing SDK errors and absolute path outputs. Co-authored-by: Copilot App <[email protected]> Copilot-Session: c88abce7-9de0-4b64-be95-984d17a5b7a5
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-task discovery changes and public API additions warrant human sign-off; reported validation was not independently verified.
0 open findings
What changed in this PR
Removes shared Android SDK discovery state so build tasks use their own resolved SDK paths, while retaining supported-version state and existing lookup behavior.
Changes:
- Adds explicit-path SDK lookup APIs and updates public API baselines.
- Keeps discovery local to
ResolveSdksand passes resolved paths to downstream tasks. - Adds regression coverage for SDK isolation, ordering, fallbacks, diagnostics, and absolute paths.
| File | Description |
|---|---|
| tests/Xamarin.Android.Tools.AndroidSdk-Tests/AndroidSdkInfoTests.cs | Tests explicit-path lookup and compatibility. |
| src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt | Records new netstandard2.0 APIs. |
| src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net11.0/PublicAPI.Unshipped.txt | Records new net11.0 APIs. |
| src/Xamarin.Android.Tools.AndroidSdk/PublicAPI/net10.0/PublicAPI.Unshipped.txt | Records new net10.0 APIs. |
| src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs | Adds shared implementations for explicit-path lookups. |
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets | Passes the resolved SDK directory. |
| src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.Nullable.cs | Removes shared SDK refresh logic. |
| src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs | Removes SDK state and uses explicit platform paths. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs | Tests task isolation, outputs, and diagnostics. |
| src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs | Uses local discovery and absolute output paths. |
| src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs | Resolves tools from the task’s SDK path. |
| src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs | Uses the explicit SDK for optional libraries. |
| src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs | Uses the explicit SDK for platform JAR lookup. |
🧠 Review effort: Balanced
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ LGTM — 0 errors, 0 warnings, 1 suggestion.
The explicit SDK path now flows consistently through SDK discovery, tooling resolution, platform-JAR lookup, manifest optional-library lookup, and jar2xml. The static helper implementations preserve ordering and platform fallback behavior, the API baselines are updated across all target frameworks, and the regression coverage exercises both SDK-root isolation and missing-path diagnostics. All 42 reported checks are green.
Generated by Android PR Reviewer for #13145 · copilot · gpt56 · 151.9 AIC · ⌖ 11.3 AIC · ⊞ 26.4K
Comment /review to run again
…te (#13201) `Xamarin.Android.Tasks.MonoAndroidHelper.SupportedVersions` is a mutable process-wide value. One project can replace the API data that another task uses. Remove that value and `RefreshSupportedVersions`, and pass `ReferenceAssemblyPaths` to each consumer. SDK discovery, Java validation, and legacy-tool cleanup are already merged in #13145, #13133, and #13161. This PR does not repeat those changes. It is the lower prerequisite for a separate nested-build optimization. **SDK and Java resolution call counts are unchanged**, including inner builds. Cache read-only `AndroidVersions` data through `IBuildEngine4` with `RegisteredTaskObjectLifetime.Build`. The key includes the task assembly identity and the absolute, original input directory list. The cache holds no task logger or mutable current-context pointer. Concurrent creation for an equal key is harmless; correctness does not depend on a cache shared across worker processes or assembly load contexts. All API-data consumers use explicit inputs: platform JAR and tooling resolution, manifests, aapt2, D8/R8, signing, jar2xml, launch activity/instrumentation, library resources, and dependency calculation. `ManifestDocument` keeps its own version resolver, with a known-version default for standalone use. Aapt2Link and library-resource generation resolve API metadata on the calling thread before yielding. The concurrency test runs 64 tasks against two different SDK/API datasets that map the same preview ID `Z` to API levels 127 and 128. It checks both JAR paths and API outputs. The aapt2 tests link two ABIs and require exactly one API lookup before `Yield`, with relative reference paths resolved from the task's captured working directory. Tests also check cache reuse, separate build engines, manifest resolver isolation, and library-resource metadata access before `Yield`.
Pull Request
title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include:Why
The primary motivation is correctness under multithreaded MSBuild execution: remove mutable static SDK discovery state.
MonoAndroidHelper.AndroidSdkis 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
ResolveSdkscan install SDK A in the field, another project'sResolveSdkscan 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
ResolveSdksexecution 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.SupportedVersionsremains 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:MonoAndroidHelper.AndroidSdkandRefreshAndroidSdk; retainSupportedVersions,RefreshSupportedVersions, all their consumers, and existing legacy API behavior. This removes one discovery-state hazard, not all task thread-safety hazards.AndroidSdkInfooverloads 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.0fallback.AndroidSdkInfoinResolveSdkswith coded logging. Preserve JDK validation inputs and NDK discovery fallbacks; emit absolute SDK/JDK/NDK/command-line-tools paths._AndroidSdkDirectoryto the existingGetJavaPlatformJarinput.No API metadata cache, static supported-version removal, nested-build forwarding/skipping, new public MSBuild properties, or performance claim is included.
Local validation
All commands ran in this PR's own worktree with its locally built Android SDK, pinned .NET SDK
12.0.100-alpha.1.26509.101, and the following process-local environment:Prepare: passed.
SDK helper tests: 21 passed, 2 platform-specific skips, 0 failed.
Additional helper target-framework/API check: passed for netstandard2.0 and net11.0, 0 warnings/errors. The preceding test command also builds net10.0.
Full local SDK BuildDotNet: passed, 0 errors (92 generated-binding/native/baseline warnings).
Focused host regression run against the final rebuilt SDK: 26 passed, 0 skipped/failed. Includes all 18
ResolveSdksTaskTests, three Debug CoreCLR basic-app locale cases, app relocation, manifest modification, a binding build, and both missing-platform-JAR diagnostic cases. Real Android builds use the supported JDK 21 path above; historical task fixtures retain their existing faux JDK versions.git diff --checkand parsing the modified targets as XML passed. The build binlog was inspected withbinlogtool. No device tests were run: this change only removes host-side SDK discovery state; no runtime/JNI/native behavior changes.