Android Studio needs JDK 7 for Android-L mac

JavaAndroidMacosAndroid Studio

Java Problem Overview


I was trying to look how my app looks in material design and I would like to use the new cards lib. My Problem is, that it's giving me this error within my gradle file and I need to fix that.

Error:compileSdkVersion android-L requires compiling with JDK 7

I downloaded jdk-7u60-macosx-x64.dmgand installed it. java -versionin Terminal is showing me that 1.7 is installed:

java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

well

ls -l `which java`

is giving me:

/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

.../current/... doesn't have a .../home. I found the .../home here:

/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

And set the path to the "SDK location" Preferences in Android Studio under "JDK location". But it's not working -- it seems that it still can't find JDK 7.

I'm using Mac OSX 10.9.3 and Android Studio (Beta) 0.8.1.

Java Solutions


Solution 1 - Java

Setting the directory to: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home in JDK settings solved my issue. I had the same problem getting started up. Hope this helps!

Solution 2 - Java

@megapoff answer is correct . But I face little difficulty to fix it . So here is the detail solution step-by-step

For Mac

  1. Download the DMG file of JDK-7 from here

  2. Click on DMG and follow the instructions . It will install and configure JDK-7 on mac .

  3. Now in your android studio go to File->Project Structure -> SDK Location .

  4. In JDK location click on browse and go to /->Library->Java->JavaVirtualMachines->jdk1.7.0_60.jdk->Contents->Home

    Note :- Its Not /System/Library it's /Library

  5. click Apply and OK .... Bingo ..... Build the project again .....

Solution 3 - Java

The other answers are very correct but I want to be more concise and clear. To prevent others from visiting this page multiple times unnecessarily.

Important* Old Path is /System/Library/Java... and New Path is /Library/Java... (Not under the System directory)

Replace old path: /System/Library/Java/JavaVirtualMachines/jdk1.6.0_0.jdk/Contents/Home

Set your new path: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

Solution 4 - Java

I haven't moved over to Android Studio, yet. I've used it for a few tests and really like it. Just haven't been able to switch over yet. I've had this sort of issue in Eclipse and that's obviously a different solution, but looking through one of my test projects, this appears to be how you go about it:

Open your project and go to File->Settings.

Under the Project Settings, expand Compiler and go to the Java Compiler option. You want to use javac and set the project bytecode version to 1.7.

Hopefully that'll do it.

Solution 5 - Java

For jdk-7u79-macosx-x64.dmg just Setting the directory to /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

Not in /System/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

Both are different

Solution 6 - Java

Instead of looking for the folder inside : /System/Library/Java/JavaVirtualMachines/

enter image description here

We have to look into :

/Library/Java/JavaVirtualMachines/

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRasalasView Question on Stackoverflow
Solution 1 - JavamegapoffView Answer on Stackoverflow
Solution 2 - Javanitesh goelView Answer on Stackoverflow
Solution 3 - Javauser3144836View Answer on Stackoverflow
Solution 4 - JavaErik NedwidekView Answer on Stackoverflow
Solution 5 - JavaAsad IftikharView Answer on Stackoverflow
Solution 6 - JavaJorgesysView Answer on Stackoverflow