Search code examples
.netxamarinazure-devopsmauicicd

MAUI / Xamarin build failing with "Microsoft.Android.Sdk.Tooling.targets(20,5): error XA0031: Java SDK 11.0 or above is required when using .NET 6"


We have an existing Azure DevOps build pipeline for a .NET Core 7 MAUI Android app that was working fine until today, 20th November 2023. We have noticed that the previous successful build was using MSBuild version 17.7.3. Today it's using 17.8.3 that I assume means it is on a server with the new VS image on it.

MSBuild version 17.8.3+195e7f5a3 for .NET
Build FAILED.
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.95\targets\Microsoft.Android.Sdk.Tooling.targets(20,5): error XA0031: Java SDK 11.0 or above is required when using .NET 6 or higher. Download the latest JDK at: https://aka.ms/msopenjdk`

Looks like this is a breaking change for Xamarin / MAUI builds in Visual Studio 2022 17.8.3, if you are building for NET 7 without explicitly saying so in a global.json file (the dotnet build step is explicitly stating framework -f net7.0-android).


Solution

  • Classic DevOps Build Step

    Fixed it by adding a Java Tool Installer step before the dotnet build step, to use Java 11 explicitly. Only using Java 11 because this is the minimum requirement - you could try using latest Java if you like - v17 at this point in time.

    enter image description here

    Settings:

    enter image description here

    YAML Syntax

    Just adding @Kuepper's answer for YAML build steps. Please give his answer the vote if it helped you.

      - task: JavaToolInstaller@0
        displayName: 'Use Java 17'
        inputs:
          versionSpec: 17
          jdkArchitectureOption: x64
          jdkSourceOption: PreInstalled