Skip to content

Move OpenJDK installation from xaprepare to MSBuild NoTargets project#11348

Open
jonathanpeppers wants to merge 7 commits into
mainfrom
jonathanpeppers/openjdk-msbuild-project
Open

Move OpenJDK installation from xaprepare to MSBuild NoTargets project#11348
jonathanpeppers wants to merge 7 commits into
mainfrom
jonathanpeppers/openjdk-msbuild-project

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

Migrates the JDK download/install from the xaprepare bootstrapper (Step_InstallAdoptOpenJDK) to a new src/openjdk MSBuild NoTargets project, modeled after src/binutils.

New src/openjdk project

  • Downloads the Microsoft OpenJDK archive (platform-specific)
  • Downloads and verifies hash of all downloads
  • Extracts and installs to $(AndroidToolchainDirectory)/jdk-21
  • Supports incremental builds via MSBuild Inputs/Outputs
  • Validates root directory and key JDK files after install
  • Handles Windows (.zip via Unzip task) and Linux/macOS (.tar.gz via tar)
  • Handles macOS Contents/Home subdirectory structure

ProjectReferences

Projects that depend on the JDK now have a ProjectReference to src/openjdk, ensuring correct build ordering:

  • src/manifestmerger (gradle + JAVA_HOME)
  • src/r8 (gradle + JAVA_HOME)
  • src/proguard-android (gradle + JAVA_HOME)
  • src/bundletool (uses jar to extract/repack)
  • src/java-runtime (uses javac, jar, java)

Cleanup

  • Deletes all 5 Step_InstallAdoptOpenJDK*.cs files
  • Removes unused constants from all Configurables partial files
  • Removes JI_JAVA_HOME usage (redundant alias for JAVA_HOME set in CI)
  • Removes xaprepare scenario steps that installed OpenJDK

jonathanpeppers and others added 2 commits May 14, 2026 09:04
Migrate the JDK download/install from the xaprepare bootstrapper
(Step_InstallAdoptOpenJDK) to a new src/openjdk MSBuild NoTargets
project, modeled after src/binutils.

The new project:
- Downloads the Microsoft OpenJDK archive (platform-specific)
- Downloads and verifies hash of all downloads
- Extracts and installs to $(AndroidToolchainDirectory)/jdk-21
- Supports incremental builds via MSBuild Inputs/Outputs
- Validates root directory and key JDK files after install
- Handles Windows (.zip via Unzip task) and Linux/macOS (.tar.gz via tar)
- Handles macOS Contents/Home subdirectory structure

Projects that depend on the JDK now have a ProjectReference to
src/openjdk, ensuring correct build ordering:
- src/manifestmerger (gradle + JAVA_HOME)
- src/r8 (gradle + JAVA_HOME)
- src/proguard-android (gradle + JAVA_HOME)
- src/bundletool (uses jar to extract/repack)
- src/java-runtime (uses javac, jar, java)

Also removes all JI_JAVA_HOME usage, which was a redundant alias for
JAVA_HOME set in CI pipelines.

Co-authored-by: Copilot <[email protected]>
…ts project

Create a new src/androidsdk MSBuild NoTargets project that runs
sdkmanager --licenses with JAVA_HOME set correctly. This project
depends on src/openjdk via ProjectReference, ensuring the JDK is
installed before sdkmanager runs.

The gradle/JDK-dependent projects now reference androidsdk instead
of openjdk directly, since androidsdk transitively depends on openjdk.

Remove the AcceptLicenses method from xaprepare Step_Android_SDK_NDK,
which was failing in CI because it ran before the JDK was installed.

Co-authored-by: Copilot <[email protected]>
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/openjdk-msbuild-project branch from 0381336 to e1571c5 Compare May 14, 2026 16:12
jonathanpeppers and others added 4 commits May 14, 2026 13:22
Test projects that import TestApks.targets call sdkmanager with
JAVA_HOME, so they need androidsdk to ensure the JDK is installed
first.

Co-authored-by: Copilot <[email protected]>
…rs.targets

Test binding projects that import Jar.targets call javac/jar with
JavaSdkDirectory, and Mono.Android imports JavaCallableWrappers.targets
which runs D8 with JAVA_HOME. Both need the JDK installed first.

Co-authored-by: Copilot <[email protected]>
ProjectReference in .targets files does not work. Add it directly to
Emulator.csproj which is the project built standalone by the CI
pipeline to start/stop the Android emulator. This ensures the JDK
is installed before sdkmanager is called.

Revert the ineffective .targets changes from the previous commit.

Co-authored-by: Copilot <[email protected]>
ProjectReference from Emulator.csproj to androidsdk is not sufficient
because the project is built standalone by the pipeline and the
reference is not resolved in time. Add an explicit build step in
setup-test-environment-steps.yaml after xaprepare to ensure the JDK
is installed and SDK licenses are accepted before any test project
that needs Java runs.

Co-authored-by: Copilot <[email protected]>
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 18, 2026 19:24
Copilot AI review requested due to automatic review settings May 18, 2026 19:24
@jonathanpeppers
Copy link
Copy Markdown
Member Author

/review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

Android PR Reviewer completed successfully!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates Microsoft OpenJDK installation from the xaprepare C# bootstrapper (Step_InstallAdoptOpenJDK*) into a new MSBuild NoTargets project (src/openjdk), modeled after src/binutils. A second new MSBuild project (src/androidsdk) takes over Android SDK license acceptance (previously AcceptLicenses in Step_Android_SDK_NDK). Projects that need a JDK at build time (manifestmerger, r8, proguard-android, bundletool, java-runtime, and the test Emulator.csproj) gain a ProjectReference to androidsdk/openjdk to enforce build ordering. The JI_JAVA_HOME alias is removed across CI, MSBuild, and test helpers, and dead OpenJDK constants are pruned from all Configurables.* partials.

Changes:

  • Add src/openjdk (download/verify/extract/install Microsoft OpenJDK) and src/androidsdk (accept SDK licenses), wired in via Xamarin.Android.sln and ProjectReferences.
  • Delete Step_InstallAdoptOpenJDK*.cs, Step_Android_SDK_NDK.AcceptLicenses, and unused MicrosoftOpenJDK*/AdoptOpenJDK*/OpenJDKInstallDir/OpenJDKCacheDir definitions; remove the OpenJDK steps from the standard and test scenarios.
  • Drop all JI_JAVA_HOME/JI_JAVA_HOME_DEFAULT usage from setup-jdk-variables.yaml, azure-pipelines-nightly.yaml, OS.InitOS, and AndroidSdkResolver; introduce a CI step that builds androidsdk.csproj to perform the JDK install + license acceptance.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
Xamarin.Android.sln Registers the new openjdk and androidsdk projects.
Configuration.props Introduces MicrosoftOpenJDKVersion/Folder/RootDirName and unconditionally sets JavaSdkDirectory to the install location.
src/openjdk/openjdk.csproj, openjdk.targets New NoTargets project that downloads, hash-verifies, extracts, and installs the Microsoft OpenJDK.
src/androidsdk/androidsdk.csproj, androidsdk.targets New NoTargets project that runs sdkmanager --licenses to accept Android SDK licenses, taking a ProjectReference on openjdk.
src/manifestmerger/manifestmerger.csproj, src/r8/r8.csproj, src/proguard-android/proguard-android.csproj, src/bundletool/bundletool.csproj, src/java-runtime/java-runtime.csproj Add ProjectReference to androidsdk so JDK is available before gradle/jar/javac steps.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Emulator.csproj Adds ProjectReference to androidsdk for test environment.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs Removes JI_JAVA_HOME lookup.
build-tools/xaprepare/.../Step_InstallAdoptOpenJDK*.cs Deletes all five OpenJDK install step files.
build-tools/xaprepare/.../Step_Android_SDK_NDK.cs Removes AcceptLicenses and its callers (now handled by androidsdk.csproj).
build-tools/xaprepare/.../Scenario_Standard.cs, Scenario_AndroidTestDependencies.cs, Scenario_EmulatorTestDependencies.cs Drops Step_InstallMicrosoftOpenJDK and updates descriptions.
build-tools/xaprepare/.../OperatingSystems/OS.cs JavaHome no longer falls back to JI_JAVA_HOME.
build-tools/xaprepare/.../ConfigAndData/Configurables*.cs Removes unused OpenJDK constants, URLs, paths, and cached fields.
build-tools/automation/yaml-templates/setup-test-environment-steps.yaml Adds a step that builds androidsdk.csproj to install JDK and accept licenses.
build-tools/automation/yaml-templates/setup-jdk-variables.yaml Stops setting JI_JAVA_HOME / JI_JAVA_HOME_DEFAULT.
build-tools/automation/azure-pipelines-nightly.yaml Switches JavaSdkDirectory arg from $(JI_JAVA_HOME_DEFAULT) to $(JAVA_HOME).

Comment thread src/androidsdk/androidsdk.targets Outdated
Comment thread src/openjdk/openjdk.targets Outdated
Comment thread src/openjdk/openjdk.targets Outdated
Comment thread src/openjdk/openjdk.targets Outdated
Comment thread src/openjdk/openjdk.targets
Comment thread src/openjdk/openjdk.targets
Comment thread Configuration.props
Comment thread src/openjdk/openjdk.targets
Comment thread src/proguard-android/proguard-android.csproj
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

✅ LGTM

Clean, well-structured migration that follows the established binutils pattern. The dependency graph (projects → androidsdkopenjdk) correctly ensures JDK is installed before any Java-dependent build step, and the removal of JI_JAVA_HOME simplifies CI without leaving dangling references.

Positive callouts:

  • SHA-256 hash verification of downloads is a good security improvement over the old code (which only checked version strings)
  • Incremental build support via Inputs/Outputs on all targets is correct
  • The separation of openjdk (download/install JDK) from androidsdk (accept licenses) is a clean abstraction
  • CI yaml cleanup (removing JI_JAVA_HOME, JI_JAVA_HOME_DEFAULT) is thorough

Issues: 0 ❌ | 0 ⚠️ | 2 💡

Generated by Android PR Reviewer for issue #11348 · ● 12.6M

Comment thread src/openjdk/openjdk.targets Outdated
Comment thread src/openjdk/openjdk.targets
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/openjdk-msbuild-project branch from 98a580f to 59f1c2a Compare May 18, 2026 19:41
Fix 1: PowerShell "y" * 10 produces one string "yyyyyyyyyy", not 10
separate lines. Use 1..10 | ForEach-Object { "y" } instead.

Fix 2: Simplify JDK installation to a single tar call that extracts
directly into the install directory using --strip-components to flatten
the archive root folder. Windows 10+ includes bsdtar which handles
both .zip and .tar.gz. On macOS, strip 3 levels (jdk-X/Contents/Home)
vs 1 level (jdk-X) on Windows/Linux.

Co-authored-by: Copilot <[email protected]>
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/openjdk-msbuild-project branch from 59f1c2a to 3eaa5df Compare May 18, 2026 19:43
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.

2 participants