Unsupported major.minor version 52.0 when renderin

2019-01-03 05:38发布

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

Unsupported major.minor version 52.0

25条回答
干净又极端
2楼-- · 2019-01-03 06:14

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

查看更多
来,给爷笑一个
3楼-- · 2019-01-03 06:15

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

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-03 06:15

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.

查看更多
倾城 Initia
5楼-- · 2019-01-03 06:17

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

查看更多
唯我独甜
6楼-- · 2019-01-03 06:17

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!

查看更多
▲ chillily
7楼-- · 2019-01-03 06:17

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

查看更多
登录 后发表回答