'Java SDK 11.0 or above is required when using .NET 6 or higher

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?



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Juan Sturla
Solution 3 Brandon Minnick