Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

"Could not run phased build action using connection to Gradle distribution"

ErrorCould not run phased build action using connection to Gradle distribution

Short answer

This message only says the IDE could not start the Gradle build; the real reason is in the Caused by lines below it. The usual reason is a JDK that does not match the build: too old for the Android Gradle plugin, too new for the Gradle version, or different between the IDE and the terminal.

  • Applies to Android Gradle plugin 8.x and 9.x, Gradle 8.14 and 9.x, JDK 17 and 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the build in a terminal with a stack trace and read the first Caused by line. It names which cause below applies.

    ./gradlew --version
    ./gradlew help --stacktrace
  2. 2Match what you see, then jump to its fix

    1. 1Android Gradle plugin requires Java 17 to run. You are currently using Java 11.The JDK is older than the Android Gradle plugin needsFix
    2. 2The Caused by line comes from Gradle itself, often after you installed a new JDK or the IDE picked up a newer one.The JDK is newer than the Gradle version supportsFix
    3. 3The build works in the terminal but fails from the IDE (or the other way round).The IDE and the terminal use different JDKs or daemonsFix

What does the error look like?

  • Could not run phased build action using connection to Gradle distribution
  • Android Gradle plugin requires Java 17 to run. You are currently using Java 11.

Cause 1 of 3

The JDK is older than the Android Gradle plugin needs

1Check

AGP 8.x needs JDK 17, and the AGP 9.5 release notes list JDK 17 as the minimum as well. In Android Studio, the JDK that runs Gradle is the one chosen in the Gradle settings; in a terminal it is JAVA_HOME, or the java on PATH.

java -version
echo "$JAVA_HOME"

2Fix

In Android Studio open Settings, Build, Execution, Deployment, Build Tools, Gradle and choose a JDK of version 17 or higher in Gradle JDK (the bundled JetBrains Runtime works). For terminal builds, point JAVA_HOME at that JDK, or set org.gradle.java.home in gradle.properties.

# gradle.properties (example path)
org.gradle.java.home=/path/to/jdk-17

3Verify

Sync again in the IDE, and check which JVM Gradle reports in the terminal.

./gradlew --version

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

The JDK is newer than the Gradle version supports

1Check

Each Gradle release runs only up to a maximum Java version: the Gradle compatibility table lists Java 24 as the highest for Gradle 8 (from 8.14) and Java 27 for Gradle 9 (from 9.8.0). Read the Gradle version from the wrapper file and compare it to java -version.

grep distributionUrl gradle/wrapper/gradle-wrapper.properties
java -version

2Fix

Either upgrade the wrapper to a Gradle version that supports your JDK (and check AGP supports that Gradle version), or run Gradle with an older JDK that the current version supports.

./gradlew wrapper --gradle-version 9.9.1
./gradlew wrapper --gradle-version 9.9.1

3Verify

The second wrapper run updates the wrapper files too. Then run the build again.

./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

Cause 3 of 3

The IDE and the terminal use different JDKs or daemons

1Check

Android Studio runs Gradle with the JDK from its Gradle settings; a terminal uses JAVA_HOME. Builds started with different JDKs or Gradle versions get separate daemons. The Gradle JDK choice is saved as gradleJvm in .idea/gradle.xml.

grep -n gradleJvm .idea/gradle.xml
./gradlew --status

2Fix

Set the Gradle JDK in the IDE and JAVA_HOME to the same JDK, or give the project a Gradle daemon JVM criteria file so every tool uses one version. Stop old daemons afterwards.

./gradlew updateDaemonJvm --jvm-version=17
./gradlew --stop

3Verify

Build again from the IDE and from the terminal; both should now use the same JVM.

./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Commit gradle/gradle-daemon-jvm.properties so every developer and CI machine uses the same JDK for Gradle.
  • Check the AGP compatibility table for the minimum Gradle and JDK before upgrading AGP.
  • Upgrade the Gradle wrapper before installing a new major JDK.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.