This is the second day of my participation in the First Challenge 2022.

Clone a MVVN project, AS open, Terminal compile error:

AGP 7. X corresponds to Gradle 7. X API. AGP 7.0: Next Major Release for the Android Gradle Plugin

Build with AGP 7.0(Android Gradle Plugin) requires JDK 11 to run Gradle, AS updated to Android Studio Arctic Fox. OpenJDK 11 is bundled with Gradle and Gradle is configured to use it by default

From the error message, you can see that there are three ways to solve this problem

0x1. AS Is manually configured

Right-click projects in turn: Open Module Settings

The old version of AS is different from the old version:

OpenJdk 11 can be downloaded here: Archived OpenJdk General-Availability Releases

Then there’s the new version:

Open the Gradle JDK and select 11

You can also go to Settings/Preferences, as shown in the figure

The above entry can also be accessed from Gradle Settings:

0x2, Modify

Run gradlew clean build. Run gradlew clean build. Run gradlew clean build.

Example # Windows\:\\Coding\\AS\\jre

# Mac, Linux exampleOrg. Gradle. Java. Home = / Library/Java/JavaVirtualMachines/JDK - 11.0.1. JDK/Contents/homeCopy the code

The advantage of this is that the computer’s global JAVA_HOME environment variable is not affected, and it can still be JDK 1.8, and the applications it depends on are not affected.

0x3. Modify JAVA_HOME

Of course, you can change the environment variable to 11, for example:

Restart AS and Terminal type gradlew -v:

As you can see, the JVM at this time is 11.0.11, and other systems modify environment variables. The example of MAC modification is as follows:

# check JDK location
/usr/libexec/java_home -V

Set environment variables
vi ~/.bash_profile

# change jdk1.8.0_172. JDK to directory 11
exportJAVA_HOME = / Library/Java/JavaVirtualMachines jdk1.8.0 _172. JDK/Contents/Homeexport PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Exit the input mode and type the following directory to save

Update the configuration file
source ~/.bash_profile
Copy the code


  • Android AGP 7.0 adaptation, start forcing JDK 11

  • Error message “Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8”