12

Every time I create a new project in Android Studio I'm met with the following build error:

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

I already know how to change the project settings to use JDK 11, but I'd like to fix this problem permanently for all new projects.

How can I get Android Studio / Gradle to use JDK 11 instead of 1.8 for all new projects?

donturner
  • 17,867
  • 8
  • 59
  • 81
  • 2
    I was able to workaround this by removing JDK 1.8 (`mv /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk /tmp/`), then doing `Android Studio-> Invalidate Caches and Restart`, however, I'd be interested to know if there's a solution which doesn't involve such a drastic step. – donturner Jan 23 '22 at 18:18
  • did you set the JAVA_HOME environment variable to your system variables – Vishal Beep Jan 24 '22 at 06:06
  • Yes, `JAVA_HOME` is set to the Java 11 SDK installation path. – donturner Jan 24 '22 at 17:48

2 Answers2

3

I had the same issue

to solve this in Android Studio

go to Menu:

File ->
 settings -> 
    build, execution , Development -> 
      build tools -> 
        gradle ->

set Gradle JDK to be Android studio default JDK (should be version 11 or select version 11)

enter image description here

JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
0

I was experiencing the same issue, and I eventually found that it was because my JAVA_HOME environment variable was set to an older JDK. I don't use java for anything but android development, so the solution in my case was to simply unset JAVA_HOME. After that, new projects defaulted to the JDK that's bundled with android studio.

How to unset your JAVA_HOME, will depend on how it was set in the first place, but in my case (macos) it was defined in ~/.zshrc — I simply removed the line starting with:

$JAVA_HOME=

If you need that variable to be defined, then you can try pointing it to a more up-to-date version of the JDK. If that's not possible either, then my guess is that you will have to continue setting the JDK on a per-project basis.

Michael Horn
  • 3,819
  • 9
  • 22