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

Note that the current version is Android Studio Arctic Fox 2020.3.1 Patch 1


After Artic Fox 2020.3.1, your Android Studio version must at least require Java11.

Say goodbye to Java1.8.

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


Then upgrade it.

My MAC is not configured directly in.bash_profile, but in.zshrc. That’s fine, you can do it in.bash_profile, there’s almost no difference.

1. Install Java11

You can download it from the official website, but it’s slow.

Prepare 1

You can download to huawei cloud JDK11, download address: repo.huaweicloud.com/java/jdk/11…

Download it and install it all the way.

Prepare 2

Then run the /usr/libexec/java_home -v command to see multiple versions, such as

The formal work

The first step

The terminal runs open ~/.zshrc

My original Java configuration

JAVA_HOME = / Library/Java/JavaVirtualMachines jdk1.8.0 _301. JDK/Contents/Home PATH = $JAVA_HOME/bin: $PATH:. CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:. export JAVA_HOME export PATH export CLASSPATHCopy the code

Step 2 Adjust the Java configuration

Export JAVA_8_HOME = / Library/Java/JavaVirtualMachines jdk1.8.0 _301. JDK/Contents/Home export JAVA_11_HOME = / Library/Java/JavaVirtualMachines/JDK - 11.0.2. JDK/Contents/Home alias jdk8 = 'export JAVA_HOME = $JAVA_8_HOME' alias jdk11='export JAVA_HOME=$JAVA_11_HOME'Copy the code

Keep it if you need it, get rid of it if you don’t

PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export PATH
export CLASSPATH
Copy the code

The third step

The terminal executes source ~/.zshrc

At this point, you can switch

Open a new terminal

To switch the version, type jdk8 or jdk11

.

.

What about Android Studio

At this point, we upgraded Java11 and also confirmed that the current system is running the JDK of Java11 through java-version.

Let’s create a new Kotlin project in Android Studio and create a new KT file. Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8

package com.lglf.myjava11kt

class Animal {
    fun eat(a) {
        println("Every day is eating, eating, eating.")}fun move(a) {
        println("Every day is a wave.")}}fun main(a) {
    var ani = Animal()
    ani.eat()
    ani.move()
}
Copy the code

To solve it

Kotlin file

Preferences > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK

The KT file is ready to run

Java file

Run directly, an error is reported

The making it incompatible with Gradle 8.0.

  • Take a look at Project Struture and reduce Android Gradle Plugin Version to 4.1.3

It didn’t work.

Subsequent settlement

  • In the gradle. XML file in the. Idea folder
  • add<option name="delegatedBuild" value="false" />, and then run it again

The Java file is up and running.