Java SDK 11.0 or above is required when using .NET 6 or higher
Asked Answered
M

8

18

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?

Mewl answered 20/9, 2021 at 18:29 Comment(2)
The screenshot shows "1.8.0.25". That's not 17. The error says you need 11 or newer, 1.8 is too old.Westbrooke
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 deployGingerich
M
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

Mewl answered 20/9, 2021 at 21:17 Comment(1)
Just as an FYI, this requirement is specified in the following article. learn.microsoft.com/en-us/dotnet/maui/get-started/installationDaunt
M
23

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!
Magnifico answered 4/10, 2022 at 10:50 Comment(0)
M
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

Mewl answered 20/9, 2021 at 21:17 Comment(1)
Just as an FYI, this requirement is specified in the following article. learn.microsoft.com/en-us/dotnet/maui/get-started/installationDaunt
U
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.

Unbated answered 20/9, 2021 at 18:40 Comment(6)
I have installed maui-check. It executes without printing something on the console, so I assume everything is ok.Mewl
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 commandUnbated
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)Unbated
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.Mewl
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 4Unbated
Well that's what I was trying to avoid, thanks for the help though!Mewl
S
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

Selfeffacement answered 30/10, 2021 at 20:57 Comment(3)
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.Fatimahfatimid
@JamesJordanTaylor You can check my answer for actual resolution.Gneiss
Downloading the Microsoft OpenJDK v11 worked for me. I had the same issue as @JamesJordanTaylor mentions aboveMeggie
C
5

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"

Clemons answered 20/11, 2023 at 21:43 Comment(2)
how to do the same in GitHubActions???Adorl
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' ```Atmolysis
D
1

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'
Depside answered 26/11, 2023 at 13:38 Comment(1)
cool this works for me also in github actionsAsteroid
V
0

Follow-up for the answer from @Mohammad-R: in Rider 2023.3 for Windows I fixed it by manually setting Java Development Kit Location in Andriod settings. Didn't work with the latest JDK 21, had to install JDK 17 to make a build. No changes to MSBuild global properties were required

settings tree screenshot

Vogler answered 15/2 at 5:27 Comment(0)
L
0

Run this command in Cmd/PowerShell to install MS Open JDK 11

winget install Microsoft.OpenJDK.11
Lychnis answered 2/8 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.