76

After merging my project with some changes from other developers I continue to get the following:

Error:Cause: com/android/build/gradle/internal/model/DefaultAndroidProject : Unsupported major.minor version 52.0

I've tried installing Java 8, and setting my project to use Java 8. If I change my JAVA_HOME to 1.8 on the command line and compile with gradle it works. If I try to use JAVA_HOME set to 1.7 and gradle it fails with the same error.

However, in Android Studio, no matter the JDK version, it continues to print that error.

Other developers are saying they are using Java 7 without issue. Other things I've tried:

gradle clean build
gradlew clean build
Reinstalling Android Studio

Another interesting symptom is that other projects in Android Studio are perfectly happy. It's just this project that has this problem.

Here are my environment settings:

OS: Mac OS X 10.9.5
Android Studio: 2.1.1
Android Studio JVM: 1.6
Project JVM: 1.7.0_75
Android SDK (Build Tools): 23.0.2
Gradle: 2.13
JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
ANDROID_HOME: /Users/me/Library/Android/sdk

I suspect it has something to do with the gradle wrapper, but I can't figure out how to get graddle wrapper to reinitialize itself using 1.7.

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138

18 Answers18

77

Try menu File - > Invalidate caches and restart. Also make sure gradle plugins are latest:

classpath 'com.android.tools.build:gradle:2.1.0'
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Stepan Maksymov
  • 2,618
  • 19
  • 31
  • 6
    While invalidating the cache didn't do it. It was the build tools gradle version that had been rev'ed. It was set to 2.2.0-alpha1 which once I rolled it back to 2.1.0 it seemed happy again! Thanks for your help. – chubbsondubs May 26 '16 at 18:14
  • 1
    set classpath 'com.android.tools.build:gradle:2.1.3', it's work. – qinmiao Sep 07 '16 at 08:57
  • Just invalidating worked for me. From AS 1.5 to 2.2.21. Thanks! – Hermandroid Oct 29 '16 at 02:33
  • 1
    I have added classpath 'com.android.tools.build:gradle:2.2.0' but still getting Error:(1, 0) Cause: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0 – Ashish Jain Mar 14 '17 at 08:31
  • 2
    @Stepan Maksymov: I am having Android Studio of version 2.3 and my class path is`classpath 'com.android.tools.build:gradle:2.3.0'` But still I am getting error. Error:(1, 1) A problem occurred evaluating project ':app'. > java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0 Can you please tell me what is the exact problem in my project? – BK19 Mar 23 '17 at 16:42
  • 3
    where to add this line ? – Abhishek Apr 22 '17 at 11:12
  • @abhishek typically that classpath should be in your top-level `build.gradle` script, in the `buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.3.3' } }` section. – qix Jul 12 '17 at 21:45
60

Set your JAVA_HOME to use jdk 1.8.

Also check your SDK location in Android Studio:

File->Other Settings->Default Project Structure->SDKs

enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Entreco
  • 12,738
  • 8
  • 75
  • 95
  • Yes, you should try to update JAVA_HOME to point to JDK 8 location. In my case, I've updated Android studio project's SDK settings, changed java version in my PATH env variable, but still this error occured. Only updating JAVA_HOME helped me. – Vadim Kotov Sep 01 '16 at 13:06
  • After upgrading from java1.7 to java1.8, just don't forget to let Android Studio know... that's my case. – Wei WANG Nov 09 '16 at 03:59
  • Good god, is that ever buried. I had changed my system environment variables, overridden JAVA_HOME in the android studio file->settings menu, but this is where the problem was. – ArtHare May 19 '17 at 00:28
  • I chose the "Use embedded JDK" and it worked. Thank you – Pontios Sep 15 '17 at 09:25
30

This got me working on my MAC:

Goto>> File > Project Structure... > SDK Location (in left column) > JDK location section: Check Use embedded JDK (recommended)

enter image description here

qix
  • 7,228
  • 1
  • 55
  • 65
thatzprem
  • 4,697
  • 1
  • 33
  • 41
  • 1
    I upgraded from an old Android Studio to Android Studio 2.3.2. Got the errors. Turns out the JDK location was pointing to a custom JDK 1.7 installation. Set it to "use embedded JDK" and the problem went away. – Alexander van Oostenrijk May 26 '17 at 14:53
  • Me as well, for Android Studio 3.0. I don't understand why its not the default when you install android studio... – mike gold Nov 13 '17 at 02:13
15

Fix for me was

1) Update android studio to latest (2.2 as of now)

2) Install SDK 24

Sourabh Saldi
  • 3,567
  • 6
  • 34
  • 57
12

Try setting the STUDIO_JDK environment variable. What has worked for me is:

launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_76.jdk

Obviously, replace 1.8.0_76 with whatever version of JDK 8 you have installed. I've been lazy and haven't taken the time to figure out the right way to make this work across reboots (I usually just have to run that every time I reboot) but that should do the trick for you.

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
7

If you're seeing this error you need to update your JDK in "Project Structure" options.

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.

Fawad
  • 93
  • 2
  • 7
5

open file "/Application/Android Studio/Contents/info.plist", find key "JVMVersion" replace it to 1.8.x (this is your Java version, before doing it, you should install JDK 1.8.x or above)

gaillysu
  • 51
  • 1
  • 2
  • Location on Mac was /Applications/Android\ Studio.app/Contents/Info.plist, replaced to the following and worked: JVMVersion 1.8* – Yuntao Aug 24 '16 at 21:14
5

What eventually worked for me was to set the gradle JVM setting.

On mac, Go to

Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle

Set the Gradle JVM dropdown to use Java 1.8. Mine was set to 1.7.

Note: I also made the SDK location change that Entreco posted, but do NOT have the JAVA_HOME environmental variable set.

Sanj
  • 850
  • 7
  • 7
3

Try File -> Project Structure -> SDK Location

I had the same problem because gradle was using my old JDK.

Adil Aliyev
  • 1,159
  • 2
  • 9
  • 22
3

Check your SDK location in Android Studio:

File->Project Structure->SDK Location

Set JDK location: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

enter image description here

2

Check your Project SDK Location if it is JAVA 1.8

than maybe you should check your Project gradle JVM setting too

Iron
  • 21
  • 1
1

I also had this problem, It's resolved when I update my JDK and change the location of JDK in android to the latest version.

File->Other Settings->Default Project Structure->JDK Location (Change to the latest version, mine is resolved after changing to jdk1.8.0_92)

0

Are you targeting N? That will require you to use java 8.

Tyler Pfaff
  • 4,900
  • 9
  • 47
  • 62
0

don't use gradle with alpha version

Mao
  • 1,398
  • 10
  • 8
0

There can be two main reasons to occur this problem.

  1. Java Version Problem

Check the compatible java version and update your development environments JDK to same version.

  1. Gradle Version Problem

This basically the problem in gradle version. Please check project gradle version is equal to gradle version that you are using in your development environment

Chinthaka Dinadasa
  • 3,332
  • 2
  • 28
  • 33
0

this problem will accure when you transfer your project to another computer and the installed google.play.service not same the figured out workaround is remove the check of the google play services from the SDK tools window, update and reset your android studio then download and reinstall them from the SDK manager tool

Hamid Jolany
  • 800
  • 7
  • 11
0

I had the same problem a while ago. It was actually caused by wrong path in the settings! Since after update, AndroidStudio 2.3 installed itself to C:\Program Files\Android\Android Studio1 and the path was set to C:\Program Files\Android\Android Studio\gradle\gradle-2.10 instead of C:\Program Files\Android\Android Studio1\gradle\gradle-2.10

Really a stupid problem, but fortunately with a simple solution .)

Jadeye
  • 3,551
  • 4
  • 47
  • 63
0

Android Studio behaves weird in the case. Even though you set the JDK version in File -> Project Structure -> SDK Location, Android Studio only uses this for compiling the files. When it runs these files it, for some reason, uses the version of java installed system wide, i.e. in usr/local/bin.

So you have to set your path variable to point to the same version of java that have set in your Android studio project settings.

export PATH="/Applications/studio.app/Contents/jre/jdk/Contents/Home/bin:$PATH"

In my case my project was configured to use java 1.8, but my system wide installation of java was java 1.7. This was causing the issue.

user3282666
  • 640
  • 1
  • 7
  • 21