Gradle cannot apply the Android application or library plugin
An 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.
Fix it fast
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 --version2Match what you see, then jump to its fix
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_HOME2Fix
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-173Verify
The JVM line in the version output shows 17 or newer.
./gradlew --versionConfirmed by developer.android.com
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.properties2Fix
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 :wrapper3Verify
Confirm the version and sync the project.
./gradlew --versionConfirmed by developer.android.com
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
Gradle fails because it does not support the Java version you run
Could not determine java version from '21.0.1'.
Gradle can only run on JDK versions it knows.
3 causes, each with a fixMobile 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
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