I've all done, setting JAVA_HOME, JAVA8_HOME, ... and i had always the error.
For me the solution was to set the version 2.1.0 of gradle to work with Jdk 1.8.0_92 and android studio 2.11
For those of you, who are still facing this.
I got this problem after I upgraded to Android Studio to 2.1.2.
I was stuck at this problem for about an hour, I tried these solutions:
multidexEnabled true
increasing the memory for deamon thread
upgraded to Java 8
I double checked the gradle scripts and found this:
compileSdkVersion 23
buildToolsVersion "24.0.0"
changed to:
compileSdkVersion 23
buildToolsVersion "23.0.3"
I don't know how this caused the error, but this did the trick for me.
Please let me know how this worked if you know the answer.
Thanks
When a higher JDK is used for compilation it creates class file with
higher version and when a lower JDK is used to run the program it
found that higher version of class file not supported at JVM level and
results in java.lang.UnsupportedClassVersionError.
How to fix
Increase the JAVA version you are using to run your program
You can follow some tricks
Call stable version classpath 'com.android.tools.build:gradle:2.1.0' // 2.3.0
Configuring Gradle
To enable the Java 8 language features and Jack for your project, enter the following in your module-level build.gradle file:
Changing to Java SDK to Java 8 worked for me.
Android Studio settings: File -> other settings ->Default project structure -> JDK location -> jdk1.8.0_71.jdk/Contents/Home
For my case, my original Android SDK Build-tools version is 24 and Andoid SDK Tools version is 25.1.7. I install Android SDK Build-tools version 23.0.3 by Andoird SDK manager.
I tried to find solution to this problem.I tried most of the solutions mentioned in this thread. However, I am not very sure why this was occurring. Probably a bug in Android Studio. Anyhow, this is what solved the problem:
Make sure to do a clean build after changing a version of Java. As it turns out Android Studio does some work when you switch the JDK but doesn't clean the workspace and creates confusion ¯\_(ツ)_/¯
This error "Unsupported major.minor version 52.0" refers to the java compiler, although the string "major.minor" looks very similar to the Android SDK version format.
On Windows platform, asides updating jdk to 1.8, make sure JAVA_HOME point to where your jdk 1.8 is installed (i.e. C:\Program Files\Java\jdk1.8.0_91).
(originally was 2.2.2)
I guess this was generated by get several people working in the same project with different versions of gradle. So check your gradle version and edit this file properly.
I also got the same error message of 'Unsupported major.minor version 52.0' when running ./gradlew makeJar to create a jar library by Android Studio 2.2.3.
After moving down the version of gradle plugin in build.gradle from 2.2.2 to 2.1.3, the error message disappeared and all worked well.
classpath 'com.android.tools.build:gradle:2.1.3'
I don't know how the higer version of gradle plugin caused the error, but this did the trick for me. please let me know how this worked if you know the answer, thanks
This occur due to incompatible java version you are using in android studio and the java version that was used with your imported project.
Go to
File->Project structure->Change jdk 1.7 to jdk 1.8 .After that Go to File->click on Invalidate cache and Restart.
Hope this helps..
And change the dependency classpath in gradle file
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
I had got the same error and I had JDK 8 set as JAVA_HOME. It turned out that I had Android SDK Build-tools rev 25.0.2 installed. I removed this and installed 23.0.2 instead and it worked for me.
Android Studio behaves weird in the case. Even though you set the JDK version in File -> Project Structure -> SDK Location, Android Studio only uses this for compiling the files. When it runs these files it, for some reason, looks at the PATH variable to find where java is installed.
If you have an older version of java installed on your system, then your PATH variable will be pointing to that older version of java.
So you have to set your PATH to point to the same version of java that have set in your Android studio project settings.
In your ~/.bashrc or corresponding profile file add this: