ChatGPT解决这个技术问题 Extra ChatGPT

Unsupported major.minor version 52.0 in my app

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?

Looks like you might be using java 8 compiled libraries with local jdk 7.
how can I fix that? @Taylor
switch to jdk 8, or use an older version of the library containing com/android/dx/command/Main
I'm not allowed to switch to jdk 8, how can downgrade the version of the library containing com/android/dx/command/Main? @Taylor
Cannot use chat from where I am.

R
Rudy Kurniawan

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


@RafaelReyes I don't know anything about building android project with maven. But since android use build tools anyway, cant you find what version your build tool version used in maven configuration?
@RudyKurniawanHi, I guess is 4.1.1.4
The newer version: buildToolsVersion "23.0.3"
it helped thanks for the answer, but what should we do if we need build 24??
for that, you should use java 8 to build your app
F
FBRNugroho

Gradle Scripts >> build.gradle (Module app)

Change buildToolsVersion "24.0.0" to buildToolsVersion "23.0.3"

source : experience


Why do you recommend this downgrade? What does it do?
Why is 23.0.3 preferable?
D
Denys Kniazhev-Support Ukraine

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.

https://i.stack.imgur.com/iLjcE.png

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

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

This solved my problem with AndroidStudio 2. I was receiving bunch of strange errors.
With the newest buildToolsVersion 25.0.1, it requires Java 8.
t
testing

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.

https://i.stack.imgur.com/eqydx.png

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


"Or set the AndroidSdkBuildToolsVersion MSBuild property to an earlier version. For example, if you also have version 23.0.3 installed, you could add the following line within the top <PropertyGroup> element in the Android project .csproj file: <AndroidSdkBuildToolsVersion>23.0.3</AndroidSdkBuildToolsVersion>" ref: releases.xamarin.com/…
J
Jorgesys

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:

https://i.stack.imgur.com/3Na5N.png

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


s
sotrh

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.


This is the first option that I could actually use, because I couldn't find the settings mentioned in other answers in Android Studio's UI. I deleted it and then created a new project and it worked.
s
sfgblackwarkrts

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

Open your eclipse installation directory Open the file eclipse.ini Modify Dosgi.requiredJavaVersion=1.6 to Dosgi.requiredJavaVersion=1.7

Hope this helps


I append "Dosgi.requiredJavaVersion=1.7" line to /Applications/eclipse/configuration/config.ini Works perfectly on my macOS Sierra
What makes you think OP's question is associated with Eclipse?
J
Jay Sidri

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.


I
IgorGanapolsky

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.


How does one do that ?
@GuidoG You need to follow the installation instructions for your specific operating system. Just Google it, and you'll get the detailed instructions. The goal is to be able to run java -version from the commandline and see it as 1.8.
c
coarist

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.


I'm on Intellij IDEA with Maven Build.
H
Habel Philip

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

Select all items in preview channels including Android SDK build tools with rev 24rc2 or 24rc4(latest) Click on Delete 'n' packages

How to turn off preview channel

In SDK manager, select Tools > options 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)


This worked for me fine. but before that I installed jdk 8 and changed the directory as described in another answer here,
How is Xamarin relevant to OP's question?
"Or set the AndroidSdkBuildToolsVersion MSBuild property to an earlier version. For example, if you also have version 23.0.3 installed, you could add the following line within the top element in the Android project .csproj file: 23.0.3"
h
haithem

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.


k
k3b

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

thats correct. when i tried to fix my travis build i found this question wich did not help me. after i found out how to fix i added this to for others with the same problem
H
Hedego

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.


this worked for me! need to have version 1.8 jdk installed and targeted
D
DanielBarbarian

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"**
    }

C
Community

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.


I'm using Maven and IntelliJ.
In this case you could change source and target to 1.7 inside configuration on maven compiler plugin
S
Swathin

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


G
GodOnScooter

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.


A
Andrea Gherardi

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.


M
Mike Playle

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.


e
ericn

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


P
PyDevSRS

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.


I
IgorGanapolsky

https://i.stack.imgur.com/bOqzx.png


D
Daniel

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.


O
OneCricketeer

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


r
rndStr

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.


R
Rachit Murarka

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.


T
Thambu Zk

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.


This doesn't necessarily solve the issue for command-line builds with Gradle.

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now