Debug School

rakesh kumar
rakesh kumar

Posted on

Flutter:Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. in flutter

android-gradle-plugin-requires-java-11-to-run-you-are-currently-using-java-1-8
android-gradle-plugin-requires-java-11-to-run-you-are-currently-using-java-1-8

Error

I downloaded the newest Android Studio, and I wanted to run the Android Jetpack Compose Project, but when I ran it, I got the error:

> 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`.
I already downloaded Java 11 and added Java 11 in gradle.properties.
Enter fullscreen mode Exit fullscreen mode

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home
The JAVA_HOME shows Java 11, but when I run, it doesn't work - /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home

How should I do?

My Android Studio version

JVM:          1.8.0_311 (Oracle Corporation 25.311-b11)
Enter fullscreen mode Exit fullscreen mode

My Java version

C:\flutter-firebase\flutter-firebase\holidaylandmark\android>gradlew --version

------------------------------------------------------------
Gradle 7.4
------------------------------------------------------------

Build time:   2022-02-08 09:58:38 UTC
Revision:     f0d9291c04b90b59445041eaa75b2ee744162586

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          1.8.0_311 (Oracle Corporation 25.311-b11)
OS:           Windows 10 10.0 x86
Enter fullscreen mode Exit fullscreen mode

My gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
Enter fullscreen mode Exit fullscreen mode

File build.gradle

Image description

Solution

C:\flutter-firebase\flutter-firebase\holidaylandmark\android>gradlew --version

------------------------------------------------------------
Gradle 7.4
------------------------------------------------------------

Build time:   2022-02-08 09:58:38 UTC
Revision:     f0d9291c04b90b59445041eaa75b2ee744162586

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          1.8.0_311 (Oracle Corporation 25.311-b11)
OS:           Windows 10 10.0 x86
Enter fullscreen mode Exit fullscreen mode

If the JVM points to version 1.8 then you should change it in settings. You can find it in Preferences → Build, Execution, Deployment → Build Tools → Gradle → *Gradle JDK.

Image description

Changing Gradle JDK to 11, Clean Project, Rebuild Project worked for me! Please also check whether your jvmTarget, sourceCompatibility and targetCompatibility is set to java 11

compileOptions { 
        sourceCompatibility JavaVersion.VERSION_11         
          targetCompatibility JavaVersion.VERSION_11    
 }  
   kotlinOptions {  
       jvmTarget = '11'  
   } 
Enter fullscreen mode Exit fullscreen mode

ANOTHER METHODS
Step 1
Image description

Step 2
Image description

ANOTHER METHODS
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8

Image description

Open the Project Structure

Image description

Image description

Image description

ANOTHER METHODS
I had that problem and I had solved it doing this:

Add the command below in gradle.properties file:

org.gradle.java.home=C:\Program Files\\Java\\jdk-18.0.1.1.
In my case:

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
org.gradle.java.home=C:\Program Files\\Java\\jdk-18.0.1.1
Then, in terminal, change the directory to android. (I use windows)

cd android
Finally, i wrote ./gradlew signingreport in terminal and i got SHA1 and SHA-256.  
Enter fullscreen mode Exit fullscreen mode

Top comments (0)