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

Hi,

After executing an upgrade gradle from Android Studio after ionic capacitor build android --prod command to make a signed release, now when trying to execute ionic cap run android -l --external the process ends with this error:

[capacitor]         A problem occurred evaluating project ':app'.
[capacitor]         > Failed to apply plugin 'com.android.internal.application'.
[capacitor]         > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
[capacitor]         You can try some of the following options:
[capacitor]         - changing the IDE settings.
[capacitor]         - changing the JAVA_HOME environment variable.
[capacitor]         - changing `org.gradle.java.home` in `gradle.properties`.

Gradle settings in Android Studio is set to Java 11. I don’t know where to look to solve this.

If I understand correctly, it only errors out when running ionic cap run android -l --external, correct?

If so, make sure your JAVA_HOME variable is set correctly in your terminal. Android Studio and the adb tools don’t use JAVA_HOME if you’ve set it manually in the IDE, but it will use JAVA_HOME from the cli. On Mac and Linux, you can check this by running echo $JAVA_HOME.

On Mac, my current Java 11 JAVA_HOME variable looks like this

/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/
1 Like

Thanks for reply.

Everything worked fine till I upgraded the gradle because Android Studio asked for that. My $JAVA_HOME var is se to:

/usr/lib/jvm/java-8-openjdk-amd64/

Ok. I’m gonna try to change the directory and post the result

Solved after installing default-jdk (sudo apt install default-jdk) and changing JAVA_HOME sys var to /usr/lib/jvm/java-11-openjdk-amd64/

2 Likes

In case anyone here is on a windows machine, this worked for me:

  1. Download most up-to-date jdk from oracle website.
  2. Create system environment variable called “JAVA_HOME” (type “view advanced system settings” in the windows search bar, click “Environment Variables”, add a new system variable.
  3. The value of the variable should be the path where you installed the jdk. Mine was C:\Program Files\Java\jdk-17.0.1
  4. Restart your IDE.
2 Likes

For me, this resolved the issue.