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.
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
- Use setup-java to install a supported JDK (Temurin 17 or the version your tooling requires).
- Confirm
JAVA_HOMEis exported for the build step. - Rebuild the Android target.
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- run: dotnet build -f net8.0-android -c ReleasePoint the build at the JDK explicitly
If multiple JDKs are present, set the directory the Android build should use.
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_HOMEso Android tasks can find Java. - Match the JDK version to the Android tooling requirement.