Skip to content

[Build.Tasks] Use SDK-defined Java version requirements - #13133

Merged
jonathanpeppers merged 3 commits into
dotnet:mainfrom
jonathanpeppers:jonathanpeppers-java-version-requirements
Oct 14, 2026
Merged

jonathanpeppers merged 3 commits into
dotnet:mainfrom
jonathanpeppers:jonathanpeppers-java-version-requirements

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

The .NET for Android SDK configures a supported JDK range, currently 21.0 through 25.0.99. Xamarin.Android.Tasks.ValidateJavaVersion instead lowered the minimum to JDK 11 whenever the Android API level was 31 or later. This allowed explicitly selected JDK 11/17 installations despite the SDK's configured minimum.

Honor $(MinimumSupportedJavaVersion) and $(LatestSupportedJavaVersion) directly, without hardcoding versions in the validator. Remove the unused legacy validator and its framework/build-tools heuristics, along with the modern validator's unused TargetPlatformVersion input. Preserve the corresponding input on <ResolveAndroidTooling/>.

Migrate the two Java-validation fixtures to the modern task. Cover JDK 11/17 rejection, JDK 21/25 acceptance, JDK 26 rejection, exact range boundaries, release-file detection, and separate java/javac process validation. Keep fake release files inside each fake JDK and use absolute fake Java executable paths so reruns do not contaminate other tests.

Remove only the obsolete English XA0031/XA0032 resources, retaining XA0031_NET and all localized files. Document the SDK-defined minimum and preserve XA0032's historical documentation link. This is an independent correctness/legacy-cleanup change; it does not include SDK-state, nested-build, cache, or concurrency refactors. No associated issue.

Local validation

Built this worktree's own SDK using pinned .NET 12.0.100-alpha.1.26509.101; the representative app targets net11.0-android. Bounded shells set DOTNET_CLI_USE_MSBUILD_SERVER=0, MSBUILDDISABLENODEREUSE=1, and DOTNET_CLI_TELEMETRY_OPTOUT=1. Focused tests set TEST_ANDROID_JDK_PATH=C:\Program Files\Android\openjdk\jdk-21.0.8. The SDK build ran with the discovered VS 18 Insiders developer environment.

The following commands are shown in CMD syntax; %LOGS% expands to C:\Users\jopepper\.copilot\session-state\d47a67e9-2b87-4c64-9b3f-955fcaa13213\files.

SDK preparation: passed (exit 0).

dotnet msbuild Microsoft.Android.slnx -t:Prepare -nr:false -v:minimal -bl:%LOGS%\java-prepare.binlog

Full SDK build: passed (exit 0), 119 warnings / 0 errors.

.\dotnet-local.cmd build Microsoft.Android.slnx -t:BuildDotNet -nr:false -v:minimal -bl:%LOGS%\java-build.binlog

Focused tests: both runs passed, 34 passed / 0 failed / 0 skipped each. The second run followed completion of the full SDK build and also verifies fixture rerun isolation.

.\dotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "FullyQualifiedName~ValidateJavaVersionTests|FullyQualifiedName~ResolveSdksTaskTests" --logger "trx;LogFileName=java-range.trx" --results-directory %LOGS%\TestResults
.\dotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "FullyQualifiedName~ValidateJavaVersionTests|FullyQualifiedName~ResolveSdksTaskTests" --logger "trx;LogFileName=java-range-rerun.trx" --results-directory bin\TestDebug\TestResults

Representative app generation: passed. Explicit JDK 17: rejected as intended (exit 1), XA0031 requiring JDK 21.0. Explicit JDK 21.0.8: passed (exit 0), 0 warnings / 0 errors; signed APK produced. The supported-JDK incremental rerun also passed. Rejecting an explicitly supplied too-old JDK is intentional; another installed JDK is not substituted silently.

.\dotnet-local.cmd new android --framework net11.0-android --output bin\TestDebug\JavaValidationApp --name JavaValidationApp --no-restore
.\dotnet-local.cmd build bin\TestDebug\JavaValidationApp\JavaValidationApp.csproj -p:JavaSdkDirectory=D:\android-toolchain\jdk-17 -nr:false -v:minimal -bl:bin\TestDebug\java-app-jdk17.binlog
.\dotnet-local.cmd build bin\TestDebug\JavaValidationApp\JavaValidationApp.csproj -p:JavaSdkDirectory="C:\Program Files\Android\openjdk\jdk-21.0.8" -nr:false -v:minimal -bl:bin\TestDebug\java-app-jdk21.binlog
.\dotnet-local.cmd build bin\TestDebug\JavaValidationApp\JavaValidationApp.csproj -p:JavaSdkDirectory="C:\Program Files\Android\openjdk\jdk-21.0.8" -nr:false -v:minimal -bl:bin\TestDebug\java-app-jdk21-rerun.binlog

binlogtool confirmed XA0031 originates from <ValidateJavaVersion/> for the JDK 17 build and that the supported build detects JDK 21.0.8. git diff --check and XML parsing of the edited targets/resources passed. No device tests are required for this host-side Java validation change.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

The modern validator lowered the SDK minimum to JDK 11 for Android API
31 and later, allowing JDK 11 and 17 despite the configured JDK 21 minimum.
Honor the SDK minimum and maximum directly, and remove the unused legacy
framework/build-tools heuristics and their obsolete resources.

Migrate the task fixtures to the modern validator, cover release-file and
java/javac version checks including range boundaries, and isolate fake JDK
release files.  Document the SDK-defined minimum and retain the historical
XA0032 documentation link.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: d47a67e9-2b87-4c64-9b3f-955fcaa13213
Copilot AI balanced review requested due to automatic review settings October 14, 2026 00:06

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

The automated tests do not reproduce the API-level condition that triggered the original JDK-minimum regression.

1 open finding
What changed in this PR

Updates Java validation to enforce the SDK-defined JDK range and removes obsolete legacy heuristics.

Changes:

  • Uses configured minimum and maximum JDK versions directly.
  • Removes legacy validator inputs/resources.
  • Expands Java validation tests and documentation.
File Description
ValidateJavaVersionTests.cs Expands JDK range and detection tests.
ResolveSdksTaskTests.cs Migrates tests to the modern validator.
ValidateJavaVersion.cs Removes API-level minimum override.
Legacy/​ValidateJavaVersion.cs Deletes obsolete legacy validator.
Resources.resx Removes obsolete English resources.
Resources.Designer.cs Removes corresponding generated accessors.
Microsoft.Android.Sdk.Tooling.targets Stops passing the removed input.
xa0032.md Marks XA0032 as historical.
xa0031.md Documents SDK-defined requirements.
index.md Updates error-code summaries.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file

🧠 Review effort: Balanced

jonathanpeppers and others added 2 commits October 13, 2026 20:43
The direct task range cases did not set TargetPlatformVersion, so they
could not catch the former API 31+ downgrade of the configured minimum.

Invoke the shipped tooling target for API 37 with a fake JDK 17 and an
SDK minimum of JDK 21.  Assert XA0031 for both release-file and process
version detection.  Temporarily restoring the old task override and
target input makes both cases fail; the fixed focused suite passes all
36 tests.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: d47a67e9-2b87-4c64-9b3f-955fcaa13213
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 14, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) October 14, 2026 17:05

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The complete ten-file correctness and separate integration review found no high-confidence blocker. Validation now honors the SDK-configured minimum and maximum directly, including explicit too-old JDK rejection without substitution. Both detection paths and the shipped-target regression cover the removed API-level downgrade; target registration, legacy removal, generated/English/localized resources, diagnostics documentation and fake-JDK isolation remain consistent.

Static integration against the actual current main target was also verified: its sole additional upstream change is an unrelated documentation-link replacement, with the executable integration graph unchanged. This is source-review approval, not a claim that reviewer builds, tests or mutation tests were executed.

@jonathanpeppers
jonathanpeppers merged commit 0c3ac24 into dotnet:main Oct 14, 2026
41 checks passed
simonrozsival pushed a commit that referenced this pull request Oct 20, 2026
…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`.
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 14, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions github-actions Bot unlocked this conversation Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants