diff --git a/build/ci/install-java.yml b/build/ci/install-java.yml new file mode 100644 index 000000000..24e08bd31 --- /dev/null +++ b/build/ci/install-java.yml @@ -0,0 +1,86 @@ +parameters: + jdkVersion: '21.0.8' + jdkDestinationDirectory: $(Agent.ToolsDirectory)/jdk21 + +steps: + - pwsh: | + $ErrorActionPreference = 'Stop' + $jdkVersion = "${{ parameters.jdkVersion }}" + $destinationDir = "${{ parameters.jdkDestinationDirectory }}" + + # Download JDK + if ($IsWindows) { + $url = "https://aka.ms/download-jdk/microsoft-jdk-$jdkVersion-windows-x64.zip" + } else { + $url = "https://aka.ms/download-jdk/microsoft-jdk-$jdkVersion-macos-x64.tar.gz" + } + + $fileName = [System.IO.Path]::GetFileName($url) + Write-Host "Downloading JDK from: $url" + Invoke-WebRequest -Uri $url -OutFile $fileName + + # Clean and create destination directory + if (Test-Path $destinationDir) { + Write-Host "Cleaning existing directory: $destinationDir" + Remove-Item $destinationDir -Recurse -Force + } + New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null + + # Extract archive + Write-Host "Extracting JDK to: $destinationDir" + if ($IsWindows) { + Expand-Archive -Path $fileName -DestinationPath $destinationDir -Force + } else { + & tar -xzf $fileName -C $destinationDir + if ($LASTEXITCODE -ne 0) { + throw "Failed to extract JDK archive" + } + } + + # Find JAVA_HOME - look for directory with bin folder or Contents/Home + $jdkDir = Get-ChildItem -Path $destinationDir -Directory | Select-Object -First 1 + if (-not $jdkDir) { + throw "No directory found in extracted JDK archive at: $destinationDir" + } + + # Check for macOS structure (jdk-version/Contents/Home) + $contentsHome = Join-Path $jdkDir.FullName "Contents" "Home" + if (Test-Path $contentsHome) { + $javaHome = $contentsHome + } + # Check for directory with bin folder + elseif (Test-Path (Join-Path $jdkDir.FullName "bin")) { + $javaHome = $jdkDir.FullName + } + # Fallback to destination directory + else { + $javaHome = $destinationDir + } + + # Verify bin directory exists + $binPath = Join-Path $javaHome "bin" + if (-not (Test-Path $binPath)) { + throw "JDK bin directory not found at: $binPath" + } + + Write-Host "JDK installed at: $javaHome" + + # Set environment variables + Write-Host "##vso[task.setvariable variable=JAVA_HOME]$javaHome" + Write-Host "##vso[task.setvariable variable=JAVA_HOME_21_X64]$javaHome" + Write-Host "##vso[task.prependpath]$binPath" + + # Verify installation by calling java directly with full path + $javaExe = if ($IsWindows) { Join-Path $binPath "java.exe" } else { Join-Path $binPath "java" } + + if (-not (Test-Path $javaExe)) { + throw "Java executable not found at: $javaExe" + } + + Write-Host "Java version:" + & $javaExe -version + if ($LASTEXITCODE -ne 0) { + throw "Failed to execute java -version" + } + displayName: Install Java ${{ parameters.jdkVersion }} SDK + workingDirectory: $(Build.StagingDirectory) diff --git a/build/ci/setup-environment.yml b/build/ci/setup-environment.yml index 1001cc235..3f2131190 100644 --- a/build/ci/setup-environment.yml +++ b/build/ci/setup-environment.yml @@ -1,7 +1,7 @@ parameters: installAndroidDependencies: false androidSdkRoot: $(Agent.TempDirectory)/android-sdk - javaSdkRoot: $(Agent.ToolsDirectory)\jdk21 + javaSdkRoot: $(Agent.ToolsDirectory)/jdk21 steps: # before the build starts, make sure the tooling is as expected. Clear the cache on shared agents @@ -44,31 +44,10 @@ steps: } displayName: Install .NET Workloads - - bash: | - if [[ -n "$JAVA_HOME_21_X64" && -d "$JAVA_HOME_21_X64" ]]; then - echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME_21_X64" - else - JDK_DIR="$(Agent.ToolsDirectory)/jdk-21" - TEMP_FILE="$(Agent.TempDirectory)/microsoft-jdk-21.tar.gz" - if [[ ! -d "$JDK_DIR" || ! -f "$JDK_DIR/bin/java" ]]; then - echo "Downloading Microsoft JDK 21 for macOS..." - mkdir -p "$JDK_DIR" - curl -L "https://aka.ms/download-jdk/microsoft-jdk-21.0.8-macos-x64.tar.gz" -o "$TEMP_FILE" - tar -xzf "$TEMP_FILE" -C "$JDK_DIR" --strip-components=4 - rm "$TEMP_FILE" - fi - echo "##vso[task.setvariable variable=JAVA_HOME]$JDK_DIR" - fi - displayName: Use Java 21 SDK (Mac) - condition: eq( variables['Agent.OS'], 'Darwin' ) - - - task: JavaToolInstaller@0 - displayName: Use Java 21 SDK (Windows) - condition: and(eq( variables['Agent.OS'], 'Windows_NT' ), ne(${{ parameters.installAndroidDependencies }}, true)) - inputs: - versionSpec: '21' - jdkArchitectureOption: 'x64' - jdkSourceOption: 'PreInstalled' + - template: install-java.yml + parameters: + jdkVersion: '21.0.8' + jdkDestinationDirectory: ${{ parameters.javaSdkRoot }} - pwsh: | if (Test-Path "${{ parameters.androidSdkRoot }}") { @@ -78,17 +57,6 @@ steps: displayName: Clean and create Android SDK directory condition: eq(${{ parameters.installAndroidDependencies }}, true) - - task: DotNetCoreCLI@2 - displayName: Install android dependencies GoogleV2 - inputs: - command: build - projects: build/scripts/provision-android/provision-android.csproj - arguments: >- - -t:InstallAndroidDependencies -p:AcceptAndroidSdkLicenses=true -p:AndroidManifestType=GoogleV2 - -p:AndroidSdkDirectory=${{ parameters.androidSdkRoot }} - -v:n -bl:output/install-android-dependencies-GoogleV2.binlog - retryCountOnTaskFailure: 3 - - task: DotNetCoreCLI@2 displayName: Install android dependencies Xamarin inputs: @@ -100,30 +68,26 @@ steps: -v:n -bl:output/install-android-dependencies-Xamarin.binlog retryCountOnTaskFailure: 3 + - pwsh: | + $ErrorActionPreference = 'Stop' + $sdkManager = Join-Path "${{ parameters.androidSdkRoot }}" "cmdline-tools" "latest" "bin" "sdkmanager" + if ($IsWindows) { + $sdkManager += ".bat" + } + + if (Test-Path $sdkManager) { + Write-Host "Accepting Android SDK licenses..." + Write-Host "y" | & $sdkManager --licenses --sdk_root="${{ parameters.androidSdkRoot }}" + } else { + Write-Host "SDK Manager not found at: $sdkManager" + } + displayName: Accept Android SDK licenses + condition: eq(${{ parameters.installAndroidDependencies }}, true) + - pwsh: | Write-Host "##vso[task.setvariable variable=AndroidSdkDirectory]${{ parameters.androidSdkRoot }}" Write-Host "##vso[task.setvariable variable=ANDROID_SDK_ROOT]${{ parameters.androidSdkRoot }}" Write-Host "##vso[task.setvariable variable=ANDROID_HOME]${{ parameters.androidSdkRoot }}" displayName: Set ANDROID_SDK_ROOT and ANDROID_HOME to ${{ parameters.androidSdkRoot }} - - ${{ if eq(parameters.installAndroidDependencies, true) }}: - - pwsh: | - $url = "https://aka.ms/download-jdk/microsoft-jdk-21.0.8-windows-x64.zip" - if ($IsMacOS) { - $url = "https://aka.ms/download-jdk/microsoft-jdk-21.0.8-macos-x64.tar.gz" - } - $fileName = [System.IO.Path]::GetFileName($url) - Invoke-WebRequest -Uri $url -OutFile $fileName - Write-Host "##vso[task.setvariable variable=JDK_21_FILE_PATH]$(Build.StagingDirectory)/$fileName" - displayName: Download Java 21 SDK - workingDirectory: $(Build.StagingDirectory) - - task: JavaToolInstaller@0 - displayName: Use Java 21 SDK - inputs: - versionSpec: '21' - jdkArchitectureOption: 'x64' - jdkSourceOption: LocalDirectory - jdkFile: $(JDK_21_FILE_PATH) - jdkDestinationDirectory: ${{ parameters.javaSdkRoot }} - cleanDestinationDirectory: true diff --git a/build/ci/variables.yml b/build/ci/variables.yml index 91ccb45af..9fcb7f3b7 100644 --- a/build/ci/variables.yml +++ b/build/ci/variables.yml @@ -19,7 +19,7 @@ variables: macosAgentPoolName: VSEng-VSMac-Xamarin-Shared # macOS VM pool name # Tool variables - dotnetVersion: '9.0.303' # .NET version to install on agent + dotnetVersion: '9.0.305' # .NET version to install on agent dotnetFrameworkVersion: 9 # The number to use for TF (eg: netX.0-android) dotnetNuGetOrgSource: 'https://api.nuget.org/v3/index.json' # NuGet.org URL to find workloads @@ -34,7 +34,7 @@ variables: extendedTestAssembly: tests/extended/bin/$(configuration)/net$(dotnetFrameworkVersion).0/ExtendedTests.dll # Extended tests compiled binary # dotnet-next test variables - dotnetNextVersion: 10.0.100-preview.6.25358.103 # .NET preview version to install + dotnetNextVersion: 10.0.100-rc.1.25451.107 # .NET preview version to install dotnetNextFrameworkVersion: 10 # The number to use for TF (eg: netX.0-android) # dnceng-public variables diff --git a/build/scripts/provision-android/provision-android.csproj b/build/scripts/provision-android/provision-android.csproj index 0555101c3..da4539fe8 100644 --- a/build/scripts/provision-android/provision-android.csproj +++ b/build/scripts/provision-android/provision-android.csproj @@ -4,6 +4,9 @@ $(_DefaultTargetFrameworkNext) + + +