Android Studio 2.2. Preview 1 error: "Please use JDK 8 or newer"
Solution 1
I ran into this issue with a previous version of Android Studio. When I first installed Android Studio I was able to reference JDK 7 in my Program Files directory.
When I upgraded Android Studio and tried to update it to point to JDK 8, which was also in my Program Files directory, I got the same behavior you are seeing. The new path never took and it still used JDK 7.
Turns out Android Studio does not like spaces in the paths to the Android SDK and the JDK. Installing the JDK in a location that does not contain any spaces allowed me to update the location through the Project Structure window.
Solution 2
If you use Android Studio 2.2 Preview 2 and have same error just check "Use embedded JDK" in SDK Location.
Solution 3
Use File -> Project Structure to set the SDK and JDK. I think you are modifying a generated file.
Also try adding this in your gradle file:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
Solution 4
if you are using 3.0.1 first enable the use embedded jdk option from File-> project structure -> enable use embedded jdk
Related videos on Youtube
der_Fidelis
Updated on August 23, 2020Comments
-
der_Fidelis over 3 years
On trying to run Android Studio 2.2 Preview 1, it gives the following error on gradle build:
Error:Please use JDK 8 or newer.
If I try and do it from the console it says:
FAILURE: Build failed with an exception.
Where: Build file 'C:\Coding\Android projects\MaterialScrollBar\app\build.gradle' line: 1
What went wrong: A problem occurred evaluating project ':app'. com/android/jack/api/ConfigNotSupportedException : Unsupported major.minor version 52.0
I've tried to change the JDK as it suggests from jdk 1.7 to 1.8, but each time I change the JDK location for the project to any other path than the one it currently has it resets back immediately. Even if I change it to other versions of 1.7 it won't change.
I've verified that the environmental variables all point to 1.8 and still no dice. AS 2.1 recognises the JDK as 1.8 for the same project.
-
der_Fidelis almost 8 yearsNope, I used exactly that menu. The text box would reset every time I opened the window.
-
Chand51 almost 8 yearsEnabling 'Use embedded JDK' in JDK Location setting helped me. My error vanished.
-
Pidikan almost 8 yearsIt fixed the issue for me too.
-
Mayur Chudasama over 7 yearsThanks bro... It saved my almost a day
-
George Mulligan almost 7 years@MichaelOsofsky This answer was to fix an issue for a particular version of Android Studio, namely Version 2.2 Preview 1. You should be using a later version of Android Studio by now and one of the other answers may work for you such as this one.
-
Michael Osofsky almost 7 yearsThanks @GeorgeMulligan, actually stackoverflow.com/a/37335399/2848676 helped--the part about
sourceCompatibility