There are two ways to solve this problem, first make sure you run your Java program in the same or higher version of JRE, on which it has compiled, and second use the cross-compilation option to create a class file compatible to a lower JRE.
UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime. How can i make above change? Project -> Properties -> Java Compiler Enable project specific settings. Then select Compiler Compliance Level to 1.7, 1.6 or 1.5, build and test your app.
Class UnsupportedClassVersionErrorThrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported. Since: 1.2 See Also: Serialized Form.
1) If you encounter UnSupportedClassVersionError, check the JRE version you are using to run program and switch to higher version for quick solution.
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
Gradle Scripts >> build.gradle (Module app)
Change buildToolsVersion "24.0.0" to buildToolsVersion "23.0.3"
source : experience
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.
It's also important to have compile options set to java7
:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
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.
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 :-)
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:
Java 8 must be required in the future for Android Studio
, so we have to start using Java 8.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With