Unsupported major.minor version 52.0 in my app

JavaAndroidMaven Plugin

Java Problem Overview


I'm trying to compile my Android project and I'm getting this error

[INFO] Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
[INFO] 	at java.lang.ClassLoader.defineClass1(Native Method)
[INFO] 	at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
[INFO] 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[INFO] 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[INFO] 	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[INFO] 	at java.security.AccessController.doPrivileged(Native Method)
[INFO] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[INFO] 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[INFO] 	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

I've been reading in other post that try to compile with Java 8 might cause that error but not my case, I have the following Java version:

java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

OS: Linux Mint (I'm not have Java 8 installed.) Build: MAVEN

Can anyone help me with this?

Java Solutions


Solution 1 - Java

I face this problem too when making new project from android studio.

I've been able to resolve this by downgrading buildToolsVersion in app gradle setting: change {module-name}/build.gradle line

> buildToolsVersion "24.0.0 rc1"

to

> buildToolsVersion "23.0.3"


@Edit:
In Android Studio 2.1 Go to File-> Project Structure->App -> Build Tool Version. Change it to 23.0.3

Do the method above, only when you are using java version 7 and for some reason do not want to upgrade to java 8 yet.

Hope this helps

Solution 2 - Java

Gradle Scripts >> build.gradle (Module app)

Change buildToolsVersion "24.0.0" to buildToolsVersion "23.0.3"

source : experience

Solution 3 - Java

Initially I had downgraded buildToolsVersion from 24.0.0 rc3 to 23.0.3, as specified in Rudy Kurniawan's answer. Then I have noticed that I have jdk 7 specified in my project settings. I have changed it to jdk 8 and now build tools 24.0.0 rc3 work.

enter image description here

It's also important to have compile options set to java7:

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

Solution 4 - Java

I installed Android Studio alongside to Xamarin Visual Studio (was already installed). After the installation (excluded SDK, because they were already installed) I started Android Studio and it downloaded, installed and added missing SDKs (after giving the path to the SDK location). As a result I got the error message on build

>java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0

As a solution I installed jdk-8u101-windows-i586.exe without JRE (because it was already installed). Before I tried the x64 version, but it disappeared ... Then you have to change the Java Development Kit location.

Change JDK location

This is done in Visual Studio by clicking Tools > Options > Xamarin > Android Settings. Here you can navigate to the correct location. In my case it was C:\Program Files (x86)\Java\jdk1.8.0_101.

Finally, clean your project and make a new build :-)

Solution 5 - Java

The problem specified:

> Exception in thread "main" java.lang.UnsupportedClassVersionError: > com/android/dx/command/Main : Unsupported major.minor version 52.

is caused when is declared inside the build.gradle, buildToolsVersion 24 and we don´t have Java 8 installed that is required for this version. To solve this problem we have to change from buildToolsVersion from 24 to maximum 23:

enter image description here

Java 8 must be required in the future for Android Studio, so we have to start using Java 8.

Solution 6 - Java

I had the same problem with my IntelliJ Maven build. My "solution" was to go into the build tools and remove the build tools 24.0.0 folder. I found it in the {android-sdk-location}/build-tools/ directory. This is not a long term fix, but this should at least get your project building again. Upgrading to Java 8 as many have suggested will be better long term.

Solution 7 - Java

I also faced this problem when making a new project in eclipse.

  1. Open your eclipse installation directory

  2. Open the file eclipse.ini

  3. Modify

     Dosgi.requiredJavaVersion=1.6 
    

to

    Dosgi.requiredJavaVersion=1.7

Hope this helps

Solution 8 - Java

What no one here is saying is that with Build Tools 24.0.0, Java 8 is required and most people have either 1.6 or 1.7.

So yeah, setting the build tool to 23.x.x would 'solve' the problem but the root cause is the Java version on your system.

On the long term, you might want to upgrade your dev environment to use JDK8 to make use the new language enhancements and the jack compiler.

Solution 9 - Java

52 is the code for JDK 8. You can see that here: http://javarevisited.blogspot.com/2015/05/fixing-unsupported-majorminor-version.html. So Gradle is expecting you to have JDK 8 as the default Java version on your machine. Newest versions of Gradle for Android won't work with Java 7.

The solution is simple: make Java 8 the default jdk version on your machine.

Solution 10 - Java

I am on Android Studio 2.0 and facing the same problem. The solution provided by Rudy Kurniawan sorted out this issue. The affected file can be located by:

"Project" -> "Android" -> "Gradle Scripts" -> "build.gradle(Module:app)"

The "Project" pane is default on the left. To find it, inspect the name of the side tabs, click it, then use the top pull down box to get to "Android". Expand the tree in the pane to find the target file. Double-click it to edit.

Solution 11 - Java

Sorry for the late reply.Hope it helps someone else

This problem is related with your SDK, not with your JDK. You can check your version information from

> Help > About > Show Details

You will get something like

> Xamarin.Android Version: 6.0.2.1 (Starter Edition) Android SDK: > X:\Android\android-sdk > > Supported Android versions: > > 4.0.3 (API level 15)

> 4.4 (API level 19)

> 6.0 (API level 23)

> SDK Tools Version: 24.4.1 > > SDK Platform Tools Version: 23.0.1 > > SDK Build Tools Version: 24 rc2 > > Java SDK: X:\Program Files (x86)\Java\jdk1.7.0_71

> java version "1.7.0_71"

> Java(TM) SE Runtime Environment (build 1.7.0_71-b14)

> Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

If you are using preview tools for building ,then you will get similar errors all over.

What to do now?

goto > Tools -> SDK manager

  1. Select all items in preview channels including Android SDK build tools with rev 24rc2 or 24rc4(latest)

  2. Click on Delete 'n' packages

How to turn off preview channel

  1. In SDK manager, select > Tools > options

  2. Uncheck Enable preview tools

And what

Back to your code Clean all and rebuild (In rare cases, you have to select build-tools from project settings page)

Solution 12 - Java

Thanks everyone for solution.

I could solve my same problem using below solution.

In my project, I added jar which were created in Java8. And my project was referring to JRE 7. When i changed project JRE to 8. My problem solved.

Steps: In eclipse, right click on project name in project explorer > build path > Libraries > click on jre version > click edit > installed JRE > add > standerd VM > select JRE home click-path (path should be localePath\java\jdk1.8.0_25\jre) > provide name > save > select same JRE for project > finish > ok Refresh/build project once > try to run your java file. it should work.

Solution 13 - Java

Get this error message on the travis build server?

I fixed my travis build with buildToolsVersion "24.0.2" using this

# travis build 
language: android

jdk:
  - oraclejdk8
  
android:
  components:
	- tools
	- build-tools-24.0.2
	- android-23

	- add-on
	- extra

script:
  - jdk_switcher use oraclejdk8
  - ./gradlew assemble

Solution 14 - Java

In my case the default jdk was 1.7 then I changed it to 1.8 by browsing to the exact folder where the updated jdk is found in.

Solution 15 - Java

From this question.

You can try to change your compiler level back to 1.7 in the IDE you're using.

  • If you're on Eclipse, go to Windows ---> Prefences then select Java and expand it then select Compiler and change the compliance level to 1.7.

  • If you're on Android Studio, you can add this to your build.gradle

     android {
         compileSdkVersion 19
         buildToolsVersion "19.0.0"
    
         defaultConfig {
             minSdkVersion 7
             targetSdkVersion 19
         }
    
         compileOptions {
             sourceCompatibility JavaVersion.VERSION_1_7
             targetCompatibility JavaVersion.VERSION_1_7
         }
     }
    

If this doesn't help, try checking other's answer in the link mentioned above and let us know what helped you.

Solution 16 - Java

I had the same problem and tried to change the version, sometimes is for the version of Android Studio in Project> Gradle Scripts> build.gradle(Module:app) you can change the version. For example:

android {
    compileSdkVersion **23**
    buildToolsVersion **"23.0.3"**

    defaultConfig {
        applicationId "com.example.android.myapplication"
        minSdkVersion **19**
        targetSdkVersion **23**
        versionCode **1**
        versionName **"1.0"**
    }

Solution 17 - Java

Your Android build tools are not properly installed. Try installing some other version of build tools and give that version in the gradle file. or you can go to this directory

C:\Users<username>\AppData\Local\Android\sdk\build-tools

and see which build tools is installed. Try changing the build tool version in the gradle file and compile the app to see if it is working.

i had 22.0.1,23.0.02 and 24.0.0 versions of build tools and only the old 22.0.1 version worked.

source: i tried it myself and it worked for me.

Solution 18 - Java

This problem stems from the fact that your build tool version and JDK won't work together. I was using JDK version 7 with build tool 24.0.1. Of course lowering build tool version may fix the problem but it is not a real fix, as upgrading your build tools in future will break it again.

You should make sure build tool version and JDK work together. I upgraded my build tool to latest (24.0.1) and installed jdk8. Make sure to set your JAVA_HOME to latest and then try clean build.

Solution 19 - Java

Got the same issue outside of Android Studio, when trying to build for Cordova using the sdk from command line (cordova build android).

The solution provided by Rudy works in this case too. You just don't downgrade the version of Build Tools from Android Studio but you do it using the android sdk manager ui.

Solution 20 - Java

I just encountered this problem.

Reverting from the "Preview Channel" versions of the SDK tools and build tools to the latest stable version fixed it.

Solution 21 - Java

Changing com.android.tools.build:gradle:2.2.0-beta1 to com.android.tools.build:gradle:2.1.2 fixed it for me.

My Android Studio version is 2.1.2, perhaps that's why

Solution 22 - Java

The Simplest solution is you have to update your JDK to latest, version . Because Cordova supports only latest JDK .

1. First of all you have to update your Android SDK. Then,

2. If you are not able to update through your terminal , Got to your Software center of Linux destro and search the Latest (which one you want to install) and install that one .

Then again run Cordova build .

It will solve the problem .

In ,my case it worked.

Solution 23 - Java

You need to go into your SDK installation directory, and make sure that the /build-tools sub-directory matches the buildToolsVersion in your app's build.gradle file: enter image description here

Solution 24 - Java

Check that you have the latest version of the SDK installed in either C:\Program Files\Java or C:\Program Files (x86)\Java

Then go to VS2015 and follow the path tools - options - Xamarin - Android settings and in the section JDK location select change and go to look for the version you have either x64 or x32.

Solution 25 - Java

I am on cordova, here's what I've done:

- rename your android project, so that there's space for new one
- update JAVA Development Kit to 1.8 (latest one in time of writing this)
- run cordova platform add android

Should work without problems now. Your app hash will change, so if you are using it f.e. for facbeook login, you will need to update it

Solution 26 - Java

I'd had this issue for too long (SO etc hadn't helped) and only just solved it (using sdk 25).

-The local.properties file proguard.dir var was not applying with ant; I'd specified 5.3.2, but a command line call and signed export build (eclipse) was using 4.7, from the sdk dir(only 5+ supports java 8)

My solution was to replace the proguard jars (android-sdk/tools/proguard/libs directory) in the sdk with a current (5+) version of proguard.

Solution 27 - Java

unsupported-major-minor-version error can be because of unsupported JDK version. Update JDK, Go to Module Settings and change the JDK path to the new one. In most of the cases, it fixes the error.

Solution 28 - Java

I had two versions of java jdk installed. Once I pointed to right version of java jdk in File->Project Structure -> SDK Location to the latest version which I had in JAVA_HOME environment variable, the issue went away.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRafael ReyesView Question on Stackoverflow
Solution 1 - JavaRudy KurniawanView Answer on Stackoverflow
Solution 2 - JavaFBRNugrohoView Answer on Stackoverflow
Solution 3 - JavaDenys Kniazhev-Support UkraineView Answer on Stackoverflow
Solution 4 - JavatestingView Answer on Stackoverflow
Solution 5 - JavaJorgesysView Answer on Stackoverflow
Solution 6 - JavasotrhView Answer on Stackoverflow
Solution 7 - Javauser6661437View Answer on Stackoverflow
Solution 8 - JavaJay SidriView Answer on Stackoverflow
Solution 9 - JavaIgorGanapolskyView Answer on Stackoverflow
Solution 10 - JavacoaristView Answer on Stackoverflow
Solution 11 - JavaHabel PhilipView Answer on Stackoverflow
Solution 12 - JavahaithemView Answer on Stackoverflow
Solution 13 - Javak3bView Answer on Stackoverflow
Solution 14 - JavaHedegoView Answer on Stackoverflow
Solution 15 - JavacristianorbsView Answer on Stackoverflow
Solution 16 - JavaGladys SanchezView Answer on Stackoverflow
Solution 17 - JavaSwathinView Answer on Stackoverflow
Solution 18 - JavaGodOnScooterView Answer on Stackoverflow
Solution 19 - JavaAndrea GherardiView Answer on Stackoverflow
Solution 20 - JavaMike PlayleView Answer on Stackoverflow
Solution 21 - JavaericnView Answer on Stackoverflow
Solution 22 - JavaPyDevSRSView Answer on Stackoverflow
Solution 23 - JavaIgorGanapolskyView Answer on Stackoverflow
Solution 24 - JavagenommaView Answer on Stackoverflow
Solution 25 - Javamate.gvoView Answer on Stackoverflow
Solution 26 - JavarndStrView Answer on Stackoverflow
Solution 27 - JavaRachit MurarkaView Answer on Stackoverflow
Solution 28 - JavaThambu ZkView Answer on Stackoverflow