"Could not run phased build action using connection to Gradle distribution"
Could not run phased build action using connection to Gradle distributionShort 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.
Fix it fast
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 --stacktrace2Match what you see, then jump to its fix
- 1
Android Gradle plugin requires Java 17 to run. You are currently using Java 11.The JDK is older than the Android Gradle plugin needsFix - 2
The 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
The 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
- 1
What does the error look like?
Could not run phased build action using connection to Gradle distributionAndroid 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-173Verify
Sync again in the IDE, and check which JVM Gradle reports in the terminal.
./gradlew --versionConfirmed by developer.android.com
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 -version2Fix
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.13Verify
The second wrapper run updates the wrapper files too. Then run the build again.
./gradlew --versionConfirmed by docs.gradle.org
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 --status2Fix
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 --stop3Verify
Build again from the IDE and from the terminal; both should now use the same JVM.
./gradlew --versionConfirmed by docs.gradle.org
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 fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
Gradle cannot apply the Android application or library plugin
Failed to apply plugin 'com.android.internal.application'.
Gradle loaded the Android Gradle plugin but could not run it.
2 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix