19

I've installed .NET 6 (version 6.0.100-rc.1.21458.32) and Visual Studio 2020 Preview (although it might be not a prerequisite).

I am trying to debug a hello-world application but I am getting a build error regarding Java.

C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.100-rc.1.12\targets\Microsoft.Android.Sdk.Tooling.targets(20,5): error XA0031: 
Java SDK 11.0 or above is required when using .NET 6 or higher. 

I've installed Java 17 setting Path as well as pointing to the Java Development Kit Location in Visual Studio settings (tools->options->Xamarin->Android Settings). Because that didn't work I've set the JDK location to Microsoft's openjdk, but it still doesn't work.

enter image description here

What's wrong here?

2
  • 3
    The screenshot shows "1.8.0.25". That's not 17. The error says you need 11 or newer, 1.8 is too old.
    – omajid
    Sep 20, 2021 at 18:53
  • I just get this "warning XA0033: Failed to get the Java SDK version because the returned value does not appear" and the it fails to deploy
    – Frank
    Aug 25, 2022 at 14:36

6 Answers 6

20

Installing Microsoft's OpenJDK 11 did the job for me.

You may notice that Visual Studio installs a version of Microsoft OpenJDK, however, you need to install the Microsoft OpenJDK 11

1
19

For those who have the same problem in Jetbrains Rider :

  1. Install OpenJDK 11 (Microsoft's OpenJDK 11 seems to be better) as mentioned by @themelis
  2. Press Ctrl + Shift + A and search MSBuild global properties or go to File > Settings > Build, Execution, Deployment > Toolset and Build
  3. Edit the MSBuild global properties and add the following property:

Name: JavaSdkDirectory Value: {OpenJDK installation directory} (mine is C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot)

enter image description here

  1. Save and Enjoy!
9

When I installed VS2022 preview 4, my configuration became C:\Program Files\Microsoft\jdk-11.0.10.9-hotspot

This can be fixed for you if you run the maui-check command (if you installed that component during visual studio installation).

If you don't have the maui-check tool, you can get it by running the dotnet tool install -g Redth.Net.Maui.Check command

Maybe you skipped a step during installation and that's why you get the error.

6
  • I have installed maui-check. It executes without printing something on the console, so I assume everything is ok.
    – Themelis
    Sep 20, 2021 at 18:42
  • 1
    That is not correct. It should print that everything is Ok. Try opening a powershell terminal with admin rights (just to make sure) and run the command Sep 20, 2021 at 18:43
  • 1
    This is official repository of the tool. And this is an example gif of the output (you don't have to use the --dev parameter) Sep 20, 2021 at 18:44
  • You were right about maui-check. Although the output points to a problem regarding .NET 5. The framework 'Microsoft.NETCore.App', version '5.0.0' (x64) was not found. That can't be it. I had .NET 5 and I assume it got upgraded after .NET 6 installation.
    – Themelis
    Sep 20, 2021 at 18:55
  • Net5 is not required for MAUI development. If you follow these steps, it should contain all that you need. If you want to make sure, uninstall any VS2022 preview or .Net6 preview before installing Visual Studio 2022 preview 4 Sep 20, 2021 at 19:09
7

Visual Studio for Mac

Here's how I got it working on macOS with Visual Studio for Mac.

Install Microsoft Open JDK

On macOS, install the Microsoft Open JDK using HomeBrew:

brew install --cask microsoft-openjdk

Configure Visual Studio for Mac

  1. In Visual Studio for Mac, select Visual Studio -> Preferences.

  2. In the Preferences window, navigate to SDK Locations -> Android -> Locations.

  3. In the Java SDK (JDK) Location: text box, enter the following:

/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
  1. Click OK

enter image description here

3
  • 6
    I followed the directions above, but it generated the following: /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home and /Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home. Neither one removed the original error. Feb 2, 2022 at 16:49
  • @JamesJordanTaylor You can check my answer for actual resolution.
    – Ramesh
    Apr 5, 2022 at 16:10
  • 1
    Downloading the Microsoft OpenJDK v11 worked for me. I had the same issue as @JamesJordanTaylor mentions above Apr 22, 2022 at 18:09
3

You may start getting this error on Azure DevOps build pipelines for MAUI/Xamarin using the new MSBuild 17.8.3 that started rolling out over the last couple of days (20 Nov 2023). Same with Github Actions.

Solution detailed here: 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"

2
  • how to do the same in GitHubActions???
    – knocte
    Nov 21 at 12:02
  • 2
    hi @knocte, I had the same problem. you can just add this action before publishing. ``` - name: Setup Java JDK uses: actions/[email protected] with: distribution: 'microsoft' java-version: '17' ``` Nov 23 at 5:45
0

For those here who use github actions:

  - name: Install .NET MAUI
    shell: pwsh
    run: |
      dotnet workload install maui --source https://aka.ms/dotnet6/nuget/index.json --source https://api.nuget.org/v3/index.json
      dotnet workload install android maui wasm-tools --source https://aka.ms/dotnet6/nuget/index.json --source https://api.nuget.org/v3/index.json
      
  - uses: actions/setup-java@v2
    with:
      distribution: 'microsoft'
      java-version: '11'

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.