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?

Themelis
  • 4,048
  • 2
  • 21
  • 45
  • 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 '21 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 '22 at 14:36

4 Answers4

19

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

Themelis
  • 4,048
  • 2
  • 21
  • 45
  • 1
    Just as an FYI, this requirement is specified in the following article. https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation – Craig Oct 06 '21 at 23:55
13

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!
Mohammad-R
  • 307
  • 2
  • 11
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.

Juan Sturla
  • 1,254
  • 1
  • 4
  • 18
  • I have installed maui-check. It executes without printing something on the console, so I assume everything is ok. – Themelis Sep 20 '21 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 – Juan Sturla Sep 20 '21 at 18:43
  • 1
    This is [official repository](https://github.com/Redth/dotnet-maui-check) of the tool. And this is an [example gif of the output](https://user-images.githubusercontent.com/271950/112761851-29f53180-8fcb-11eb-92be-c843c794b2af.gif) (you don't have to use the --dev parameter) – Juan Sturla Sep 20 '21 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 '21 at 18:55
  • Net5 is not required for MAUI development. If you follow [these steps](https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation), 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 – Juan Sturla Sep 20 '21 at 19:09
  • Well that's what I was trying to avoid, thanks for the help though! – Themelis Sep 20 '21 at 19:23
6

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

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
  • 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. – James Jordan Taylor Feb 02 '22 at 16:49
  • @JamesJordanTaylor You can check my answer for actual resolution. – Ramesh Apr 05 '22 at 16:10
  • 1
    Downloading the Microsoft OpenJDK v11 worked for me. I had the same issue as @JamesJordanTaylor mentions above – Ken Pespisa Apr 22 '22 at 18:09