Skip to content

JDK 11 Warning

Jonathan Pryor edited this page Sep 1, 2021 · 7 revisions

Xamarin.Android 12.0 adds support for Android 12/API-31.

APIs added to Android 12/API-31 may be used by changing the $(TargetFrameworkVersion) MSBuild property to v12.0:

<PropertyGroup>
  <TargetFrameworkVersion>12.0</TargetFrameworkVersion>
</PropertyGroup>

Building for Android 12/API-31 requires the use of JDK-11 in order to build apps. See the Installing JDK-11 section for details.

However, configuring Visual Studio 2019 or Visual Studio for Mac 8 to use JDK-11 will prevent other features from working correctly. See the JDK 11-Caused Regressions section for details. It will not be possible to target Android 12.0/API-31 and use e.g. the Xamarin.Android Designer at the same time. This will be fixed in a future release.

JDK 11-Caused Regressions

When Visual Studio 2019 or Visual Studio for Mac 8.10 is configured to use JDK-11, certain Visual Studio features will not work properly.

Xamarin.Android Designer when JDK-11 is used

The Xamarin.Android Designer does not work with JDK-11. When Visual Studio is configured to use JDK-11 and a layout .xml file is opened within the Xamarin.Android Designer, the renderer will display an error message.

In Visual Studio 2019, the Xamarin.Android Designer will display:

Xamarin.Android Designer error message on Windows

In Visual Studio for Mac 8.10, the Xamarin.Android Designer will display:

Xamarin.Android Designer error message on macOS

Configuring JDK-11

JDK-11 will not be installed by default in Visual Studio 2019 and Visual Studio for Mac 8.10.

If Visual Studio is not configured to use JDK-11 and $(TargetFrameworkVersion)=v12.0, then the build will fail with an XA0031 error:

error XA0031: Java SDK 11.0 or above is required when using $(TargetFrameworkVersion) v12.0.
Note: the Android Designer is incompatible with Java SDK 11.0: https://aka.ms/vs2019-and-jdk-11

If you have not already installed JDK-11, download a JDK-11 installer. We recommend using the Microsoft Build of OpenJDK:

Once an appropriate JDK-11 installer has been downloaded it, install JDK-11.

Once JDK-11 has been installed, the JDK path can be configured within Visual Studio.

Visual Studio 2019

Within Visual Studio 2019:

  1. Click Tools > Options…
  2. Within the left-hand tree of the Options dialog box, select Xamarin > Android Settings: Visual Studio 2019 Options Dialog
  3. Within the right-hand panel of the Options dialog box, click the button next to the Java Development Kit Location path. This presents the JDK Configuration dialog box: Visual Studio 2019 JDK Configuration Didalog
  4. Within the JDK Configuration dialog box, select the Configure an existing JDK installation (Advanced Users) radio button, then click the Browse button.
  5. Within the Browse For Folder dialog box, navigate to C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot, then click OK.
  6. Back within the JDK Configuration dialog box, click Continue
  7. Back within the Options dialog, click OK.

Builds after this point will use JDK-11.

To use JDK 1.8, follow steps (1)…(3), then:

  1. Within the JDK Configuration dialog box, select the Use the default installed Microsoft OpenJdk radio button, then click Continue.

Visual Studio for Mac 8.10

Within Visual Studio for Mac 8.10:

  1. Click Visual Studio > Preferences…
  2. Within the left-hand tree of the the Preferences dialog, select Projects > SDK Locations > Android.
  3. Within the right-hand panel of the Preferences dialog, select the Locations tab. Visual Studio for Mac Preferences Dialog
  4. Click the button to the right of Java SDK (JDK) Location. This opens a directory selection window.
  5. Within the directory selection window, press Command+Shift+G and Go to the folder /Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home, then click Select Directory.
  6. Within the Preferences dialog, click OK.

Builds after this point will use JDK-11.

To use JDK 1.8, follow steps (1)…(3), then click the Reset to Defaults button.

Clone this wiki locally