Android Studio is giving me a Gradle build error that looks like this:
Error:(3, 22) compileSdkVersion android-22 requires compiling with JDK 7
Now it gives me these clickable prompts:
Download JDK 7 Select a JDK from the File System Open build.gradle File
And I have already downloaded and installed JDK 7. The problem is when I go to select it in the "File System" i can only find a directory named 1.6.0 JDK. Furthermore, the installation of JDK 7 skipped the bullet point where I would've selected the install directory, so I'm really not sure where it is. My java control panel says I have "Java 7 Update 79" so I'm pretty sure I'm close, I just need to tell android studio where it is. I also ran the java -version
command in the terminal and it says my version is "1.7.0_79".
Any help would be appreciated!
Up to Android Studio 3.5 beta 2 one could use JDK11 for compiling project by configuring it in Project Structure -> SDK Location -> JDK Location. This way Android Studio is run under bundled JDK8 but Gradle is using selected JDK11. Starting from Android Studio 3.5 beta 3 this setup is no longer supported.
Java 8 language features are now supported by the Android build system in the javac/dx compilation path. Android Studio's Gradle plugin now desugars Java 8 class files to Java 7-compatible class files, so you can use lambdas, method references and other features of Java 8.
As per the docs, JDK 17 isn't supported yet in Android Studio.
You can use cmd + ; for Mac or Ctrl + Alt + Shift + S for Windows/Linux to pull up the Project Structure dialog. In there, you can set the JDK location as well as the Android SDK location.
To get your JDK location, run /usr/libexec/java_home -v 11
in terminal. Send 1.7 for Java 7, 1.8 for Java 8, or 11 for Java 11.
In Android Studio Arctic Fox (2020.3.1 Patch 4), the JDK Location setting is moved to:
File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK
You can follow the answer from Ben Kane, the JDK Location setting is located in:
File > Project Structure > SDK Location
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With