I\'m trying to compile my Android project and I\'m getting this error
[INFO] Exception in thread \"main\" java.lang.UnsupportedClassVersionError: com/android
Gradle Scripts >> build.gradle (Module app)
Change buildToolsVersion "24.0.0" to buildToolsVersion "23.0.3"
source : experience
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 :-)
I also faced this problem when making a new project in eclipse.
Modify
Dosgi.requiredJavaVersion=1.6
to
Dosgi.requiredJavaVersion=1.7
Hope this helps
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 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.
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.
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.