107

When I try to render a layout preview in Android Studio I get error:

Unsupported major.minor version 52.0

Ivo Stoyanov
  • 16,256
  • 8
  • 62
  • 65
  • You shouls state the Operating System and Java version. Update to a newer version of Java. If on Debian, be sure to use Debian Stretch (8.9, Java 8) instead of Debian Jessie (8.1, Java 7). – jww Apr 10 '19 at 17:37

25 Answers25

100

Check your JAVA_HOME to use jdk 1.8

Also check : the parameter in Android Studio in order to change at

File->Other Settings->Default Project Structure->SDKs

Apostolos
  • 10,033
  • 5
  • 24
  • 39
Fredblabla
  • 1,029
  • 1
  • 6
  • 5
  • 5
    Hi, I have the jdk1.8 installed and "linked" in Project Structure and the problem still happens – Kotik_o Apr 12 '16 at 12:21
  • Your answer is nice, but maybe add that when you open Project Structure, you see an overview of the current problems such as the JDK version. – jobbert Jun 06 '16 at 14:14
  • 1
    Thanks; just installing JDK 8 and setting it in Default Project Structure worked for me. – pipedreambomb Jul 23 '16 at 13:19
  • 1
    On OSX, I set JAVA_HOME to /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home, solved the problem. – Zhang Buzz May 25 '17 at 06:36
  • I've found that setting `JAVA_HOME` is not necessary, but using `File->Project Structure` is. Also you can set the value to 'Use embedded JDK'. – ThomasW Aug 10 '17 at 07:12
  • I solved the issue by two ways. 1) Either update sdk components and Java Sdk to latest version or 2) Change the gradle plugin to lower version so that both gradle plugin and build tool you are using become compatible. I got this error with gradle plugin 2.3.3 with build tool 23.0.1 and solved when I used gradle plugin 2.1.2 with same build tool version. – Karan Nagpal Sep 30 '17 at 11:48
70

This is bug in Android Studio. Usually you get error: Unsupported major.minor version 52.0

WORKAROUND: If you have installed Android N, change Android rendering version with older one and the problem will disappear.

SOLUTION: Install Android SDK Tools 25.1.3 (tools) or higher

enter image description here

Ivo Stoyanov
  • 16,256
  • 8
  • 62
  • 65
41

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

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0'
    //classpath 'com.android.tools.build:gradle:2.+'
}
Brad
  • 9,113
  • 10
  • 44
  • 68
FeelCode
  • 491
  • 4
  • 5
  • 1
    I've googled for 2hours to solve this problem. You saved my life! – Soohwan Park Jun 15 '16 at 09:38
  • YES! This solved it for me as well, none of the other suggested answers worked. I had the problem on a project that was a few months old and when I tried to open it on a new computer with fresh Android Studio. – Mattias Petter Johansson Jul 18 '16 at 20:10
  • This worked for me thanks..!! But why it gave error to me. Following classpath i have set classpath 'com.android.tools.build:gradle:2.3.0-alpha2' – Parin Parikh Dec 23 '16 at 05:49
36

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:

  1. multidexEnabled true
  2. increasing the memory for deamon thread
  3. 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

karan vs
  • 3,044
  • 4
  • 19
  • 26
28

Unsupported major.minor version 52.0

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:

android {
  ...
  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Courtesy goes to Java 8 Language Features

Just select "API 23: Android 6.0" from preview section .

enter image description here

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • @fantasy mine pleasure . – IntelliJ Amiya Oct 07 '16 at 05:56
  • I had to lower gradle and include the Java jack options. However I still don't comprehend why the error happens and how will it be solved in the future. I have everything updated to the latest versions :/ – htafoya Dec 26 '16 at 23:49
25

If you're seeing this error and you just upgraded to Android Studio 2.2+ you need to update your JDK in "Project Structure" options.

On OSX, this is found under File > Project Structure > SDK. Or from the welcome screen in Configure > Project Defaults > Project Structure.

Select the Use the embedded JDK (recommended) option instead of using your own JDK.

Google's docs aren't yet updated to reflect this change. See: http://tools.android.com/tech-docs/configuration/osx-jdk

Will Vanderhoef
  • 779
  • 7
  • 12
7

Im my case I had to change the dependencies of the build.gradle file to:

dependencies { 
    classpath 'com.android.tools.build:gradle:2.1.0'
}

(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.

Good vibes!

Jeremy Wiebe
  • 3,894
  • 22
  • 31
Sebastian Corradi
  • 1,353
  • 2
  • 14
  • 25
7

With the latest version, you are recommended to switch to the embedded JDK like in the image below, and this will solve your error

resolve major.minor version 52.0 error

MatPag
  • 41,742
  • 14
  • 105
  • 114
  • I didn't care for all the janking around with different SDK and JDK versions recommended here, but was about to do that and discovered the "Use embedded JDK" option, which worked. I was going to post that solution and saw yours. This should be the correct solution, IMHO. – David Gish Mar 10 '17 at 17:19
  • Same than @DavidGish this solution nailed it – Jeremy Piednoel Aug 19 '17 at 23:05
4

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

Paul Y
  • 41
  • 1
4

1、make sure Gradle Gradle JVM Version enter image description here

2、make sure ProjectSettings SDKs Veriosn enter image description here

lingyfh
  • 1,363
  • 18
  • 23
3

For me, updating the Android Studio to the latest version solved the problem.

3

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:

In Application level build.gradle, removed:

  classpath 'com.android.tools.build:gradle:2.2.0-beta1'

replaced with:

classpath 'com.android.tools.build:gradle:2.0.0'
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
sid_09
  • 461
  • 4
  • 18
2

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
}
DarkCygnus
  • 7,420
  • 4
  • 36
  • 59
Anshul Aggarwal
  • 609
  • 6
  • 6
1

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

meeza
  • 664
  • 1
  • 9
  • 20
1

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 ¯\_(ツ)_/¯

Alex Styl
  • 3,982
  • 2
  • 28
  • 47
1

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).

somard
  • 51
  • 4
1

I had to update Java version to JDK 8 at Jenkins->Manage Jenkins->Global Tool Configuration->JDK.

ViliusK
  • 11,345
  • 4
  • 67
  • 71
1

Changing to Java SDK to Java 8 and worked for me

Android Studio settings:

File > other settings > Default project structure > JDK location > jdk1.8.0_71.jdk/Contents/Home enter image description here

1

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:

export PATH="/Applications/studio.app/Contents/jre/jdk/Contents/Home/bin:$PATH"

In my case my project was configured to use java 1.8, but my system wide installation of java was java 1.7. This was causing the issue.

user3282666
  • 640
  • 1
  • 7
  • 21
0

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.

Modify these 2 lines to:

buildToolsVersion "23.0.3" compileSdkVersion 24

Then it works!

0

Download latest JDK and install. Go toVS2015 Tools > Options > Xamarin and change the java to the latest JDK location

Marco Duindam
  • 135
  • 2
  • 8
0

Also, if issue appears while executing ./gradlew command, setting java home in gradle.properties file, solves this issue:

org.gradle.java.home=/usr/java/jdk1.8.0_45/

ViliusK
  • 11,345
  • 4
  • 67
  • 71
0

For me the problem was that the version of gradle in build.gradle was not same as the actual gradle version I had installed.

dependencies { classpath('com.android.tools.build:grade:2.2.0') { force = true}

Check your installed gradle versions at /Contents/gradle/m2repository/com/android/tools/build/gradle/ and change the above build.gradle file with

classpath('com.android.tools.build:grade:1.5.1') or <>

rarejewel
  • 26
  • 1
  • 4
0

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.

Marouane Gazanayi
  • 5,063
  • 6
  • 39
  • 58
Zela
  • 1
-1

change to
buildToolsVersion "23.0.2" in app gradle file.

Sangram Haladkar
  • 707
  • 9
  • 22