14

I have tried all the possible solutions for this error. Require guidance here:

I am using Windows Laptop : Android Studio 2020.3.1.22

Below is the build.graddle file:

plugins { id 'com.android.application' id 'kotlin-android' } android { compileSdk 31 defaultConfig { applicationId "com.example.myapplication3" minSdk 21 targetSdk 31 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { // Flag to enable support for the new language APIs coreLibraryDesugaringEnabled = true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } } dependencies { implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5") } 

also my graddle wrapper properties:

distributionBase=GRADLE_USER_HOME distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME 

my output of ./gradlew --version

Gradle 7.0.2 ------------------------------------------------------------ Build time: 2021-05-14 12:02:31 UTC Revision: 1ef1b260d39daacbf9357f9d8594a8a743e2152e Kotlin: 1.4.31 Groovy: 3.0.7 Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020 JVM: 1.8.0_275 (Azul Systems, Inc. 25.275-b01) 

Android Sdk version: C:\Users\User name\AppData\Local\Android\Sdk Gradle JDK: 11 version 11.0.12 C:\Program Files\Java\jdk-11.0.12

Java Version:

C:\Users\Vainav Shah\StudioProjects\MyApplication3>java --version java 16.0.2 2021-07-20 Java(TM) SE Runtime Environment (build 16.0.2+7-67) Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing) 

Please guide to resolve this error: An exception occurred applying plugin request [id: 'com.android.application']

Failed to apply plugin 'com.android.internal.application'. Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. You can try some of the following options: - changing the IDE settings. - changing the JAVA_HOME environment variable. - changing org.gradle.java.home in gradle.properties.

5
  • Have you seen this? stackoverflow.com/questions/66980512/… Commented Aug 10, 2021 at 14:49
  • 4
    Have you tried setting it from within Android Studio? Settings -> Build,Execution & Deployment -> Build Tools -> Gradle. And change the Gradle JDK to a JDK 11 installation. Commented Aug 10, 2021 at 14:49
  • yes done! Gradle JDK: 11 version 11.0.12 C:\Program Files\Java\jdk-11.0.12 Still the same issue Commented Aug 10, 2021 at 14:55
  • Did you try to Invalidate cache and restart android studio? Commented Aug 10, 2021 at 14:58
  • Yes! 2-3 times No effect :( Commented Aug 11, 2021 at 6:23

5 Answers 5

31

Well I also face same issue

Image showing same error

What worked for me is this (In Windows 10 OS based Laptop)

Go to File-->Settings-->Build,Execution,Deployment-->Build Tools-->Gradle

Now here -->Gradle JDK change 1.8 to 11(given in dropdown).

See image given to get more clear idea.

Steps to get Answer to given problem

After that just REBUILD YOU PROJECT. It worked for me. (see attached image). Screen showing every thing is fine now and answer worked properlly.

SO ERROR IS SOLVED AND EVERY THING IS FINE IN PROJECT NOW.

HOPE THIS WORKS FOR YOU TOO! THANKS.

Sign up to request clarification or add additional context in comments.

3 Comments

problem solved!
I tried this many times but this is not working for me can you suggest any other things to help this am getting this error "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8." in cmd can you help me to solve this @SaiAbhijit
Also You can see Video here youtu.be/9mmY8rLvoRU
2

For Windows -> File-> Settings-> Build,Execution,Deployment-> Build Tools-> Gradle-> Gradle JDK and select java 11

Comments

2

This error happened to me while I was using Jetpack Compose and it required java 11, but I was using java 1.8. So if you cannot find jdk 11 in dropdown that means you have not downloaded it yet, so click download jdk and download 11 and click apply).

Comments

2

Add the JavaHome path to wrapper.properties

Changing the Gralde JDK from Android Studio Preferences didn't work for me.

But I was able to correct the JDK by adding the org.gradle.java.home path in the gradle-wrapper.properties file.

distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip # I had to add this line (macos) org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home 

I found the JAVA_HOME path by going to File -> Project Structure -> SDKs -> Choose the JDK you want to use -> JDK home path.

enter image description here

After that, I was able again to run gradlew commands.

1 Comment

This fixed my problem. I use flutter and Mac
1

Just change jvmTarget to 11, like bellow code.

kotlinOptions { jvmTarget = '1.8' } 

change '1.8' to '11'

kotlinOptions { jvmTarget = '11' } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.