Maaz Zindani

Loading the index…

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

Gradle cannot apply the Android application or library plugin

ErrorAn exception occurred applying plugin request [id: 'com.android.application']

Short answer

Gradle loaded the Android Gradle plugin but could not run it. The message under it names the reason: the JDK that runs Gradle is older than the plugin needs, or the Gradle version is below the plugin's minimum.

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

Fix it fast

  1. 1Find out which cause you have

    Read the line directly under 'Failed to apply plugin'. Then check which Java and Gradle the build actually runs.

    ./gradlew --version
  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.Gradle runs on a JDK older than the plugin requiresFix
    2. 2The message under the error says a newer Gradle version is requiredThe Gradle wrapper version is below the plugin's minimumFix

What does the error look like?

  • An exception occurred applying plugin request [id: 'com.android.application']
  • Failed to apply plugin 'com.android.internal.application'.
  • Android Gradle plugin requires Java 17 to run. You are currently using Java 11.

Cause 1 of 2

Gradle runs on a JDK older than the plugin requires

1Check

AGP 8.x needs JDK 17 and AGP 9.5 lists 17 as its minimum. The JDK that counts is the one running Gradle, which is not always the one the IDE uses.

./gradlew --version
echo $JAVA_HOME

2Fix

In Android Studio, open Settings, then Build, Execution, Deployment, then Build Tools, then Gradle, and choose JDK 17 or newer as the Gradle JDK. For the terminal, point JAVA_HOME (or org.gradle.java.home in gradle.properties) at the same JDK.

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

3Verify

The JVM line in the version output shows 17 or newer.

./gradlew --version

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 2

The Gradle wrapper version is below the plugin's minimum

1Check

Each Android Gradle plugin release has a minimum Gradle version; AGP 9.5 lists 9.6.0. Compare it with distributionUrl.

cat gradle/wrapper/gradle-wrapper.properties

2Fix

Raise the wrapper to the version the plugin needs. Run the task twice so the JAR and scripts update as well.

./gradlew :wrapper --gradle-version 9.6.0
./gradlew :wrapper

3Verify

Confirm the version and sync the project.

./gradlew --version

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Set the Gradle JDK and JAVA_HOME to the same JDK on every machine and in CI.
  • Check the AGP compatibility table before upgrading Android Studio, Gradle or the plugin.
  • Declare plugins in a plugins block with full ids, and keep versions in one catalog.

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.