How do I fix a Java/Gradle incompatibility error in a Codemagic Android build?

Last updated: October 15, 2026

Context

When running an Android build on Codemagic, you may encounter an error similar to the following:

The Java version used for the build is 21.0.9, which is incompatible with Gradle 8.0.

This typically happens when the project configuration overrides the default Java version on the build machine (Java 17) with a version that is incompatible with the Gradle version specified in the project.

Answer

To resolve this issue, check the following files in your project for any explicit Java/JDK version settings:

  • android/gradle/wrapper/gradle-wrapper.properties — verify which Gradle version is being used.

  • Any other project-level configuration that may be explicitly setting the JDK or Java version.

You then have two options to fix the incompatibility:

  1. Keep using Java 17 — Ensure your project is not overriding the default Java 17 version on the Codemagic build machine. Java 17 is compatible with Gradle 8.0.

  2. Upgrade to Java 21 and update Gradle — If you want to use Java 21, upgrade your project's Gradle version to at least 8.4 (and ensure your Android Gradle Plugin version is compatible). Then explicitly set the Java version in your codemagic.yaml:

    android-workflow:
        name: Android Workflow
        instance_type: mac_mini_m2
        environment:
          java: 21

Additionally, it is recommended to add the following step to your workflow to ensure the Flutter SDK path is correctly configured in android/local.properties:

- name: Set up local.properties
  script: |
    echo "flutter.sdk=$HOME/programs/flutter" > "$CM_BUILD_DIR/android/local.properties"

Note: This step is unrelated to the Java/Gradle incompatibility but is needed for the Android project to correctly locate the Flutter SDK on the Codemagic build machine.