Skip to content
Latchkey

MAUI Android "JavaSdkDirectory ... not found / java.exe not found" in CI

The MAUI Android toolchain runs Java-based tools and needs a JDK. When JAVA_HOME is unset, missing, or points at an unsupported JDK version, the build fails reporting that the Java SDK directory or java executable cannot be found.

What this error means

A MAUI Android build fails with a message that the Java SDK could not be found (for example "JavaSdkDirectory" not located or "java.exe" / "java" not found), often after Android SDK setup.

Xamarin.Android
error XA0031: Java SDK 17.0 or above is required when targeting this Android API level.
error : Could not find Java SDK directory. Set the 'JavaSdkDirectory' or JAVA_HOME.

Common causes

JAVA_HOME is unset or wrong

The build cannot find a JDK because JAVA_HOME is not exported, so the Android tasks have no Java to run.

An unsupported JDK version is selected

Recent Android build tooling needs a specific minimum JDK (such as 17). An older default JDK on the runner is rejected.

How to fix it

Set up the right JDK and export JAVA_HOME

  1. Use setup-java to install a supported JDK (Temurin 17 or the version your tooling requires).
  2. Confirm JAVA_HOME is exported for the build step.
  3. Rebuild the Android target.
.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: 'temurin'
    java-version: '17'
- run: dotnet build -f net8.0-android -c Release

Point the build at the JDK explicitly

If multiple JDKs are present, set the directory the Android build should use.

Terminal
dotnet build -f net8.0-android -p:JavaSdkDirectory="$JAVA_HOME"

How to prevent it

  • Install a supported JDK with setup-java in CI.
  • Export JAVA_HOME so Android tasks can find Java.
  • Match the JDK version to the Android tooling requirement.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →