Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:compileSdkVersion android-21 requires compiling with JDK 7

Tags:

android

macos

While compiling i get the error Error:compileSdkVersion android-21 requires compiling with JDK 7, saying that a newer version of JDK is required.

I'm running on OS X Yosemite with Android Studio v0.8.14

Things I checked :

  1. Java version :

java version "1.8.0_25" Java(TM) SE Runtime Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

  1. Inside the JavaVirtualMachine folder I can see only 1.6.0.jdk folder, I cannot find any other folder.

  2. Tried reinstalling JDk 8 and 7!

I'm unable to find the folder location of jvm 1.8, any idea how I can fix there.

like image 207
Arjun Komath Avatar asked Nov 01 '14 12:11

Arjun Komath


3 Answers

The Exact Fix for this Issue (Android Studio Users on Mac)

If you have already upgraded to Java 8, please note that the JDK location is now within /Library/Java compared to Java 6's location /System/Library/Java. So to fix this problem, Right click on the Project folder > Project Structure > SDK Location.

Then change JDK location to

/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

If you have installed a different JDK version (other than Java 8), find out the path using the java_home script first and use the output. Just run,

/usr/libexec/java_home 
like image 178
C-- Avatar answered Nov 15 '22 05:11

C--


Actually I just found the solution - JDK 7 is in /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home.

that got it working for me. Oracle Docs on where JDK7 is installed

like image 21
gsueagle2008 Avatar answered Nov 15 '22 06:11

gsueagle2008


I got a solution. It happened with me too and I searched a lot on Google but all I got was hints. A lot of hints. And I came up with a sure shot solution.

This is because the computer doesn't have JDK 7 (or greater) installed. The JDK directory in AS/Configuration might points to JDK6. (That System/Library/...)

All you need to do is:

  1. Download latest JDK.
  2. Install it.
  3. Point Android Studio/Configure/Project Defaults/Project Structure/(JDK Location: ) to /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

Text highlighted in bold-italics may differ, so it's recommended that you browse it. Hope this helps. Spent a whole day messing up with gradle, android studio. Happy coding.

like image 10
TheOnlyAnil Avatar answered Nov 15 '22 04:11

TheOnlyAnil