Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 201
Themelis Avatar asked Sep 20 '21 18:09

Themelis


People also ask

Do I need SDK for Java?

For example, to develop applications in Java, you need a Java SDK (JDK). SDKs contain binaries, source code for the binaries, and documentation for the source code. JDK builds also contain annotations. Generally, SDKs are global.

Do I need both JDK and SDK?

There's no difference between JDK and Java SDK. Both of them mean the same thing.


3 Answers

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

like image 64
Themelis Avatar answered Oct 21 '22 02:10

Themelis


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.

like image 26
Juan Sturla Avatar answered Oct 21 '22 01:10

Juan Sturla


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

like image 37
Brandon Minnick Avatar answered Oct 21 '22 01:10

Brandon Minnick