Error:compileSdkVersion android-21 requires compiling with JDK 7

后端 未结 9 1209
逝去的感伤
逝去的感伤 2020-12-02 07:44

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 r

相关标签:
9条回答
  • 2020-12-02 07:49

    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.

    0 讨论(0)
  • 2020-12-02 07:51

    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

    0 讨论(0)
  • 2020-12-02 08:02

    I am sharing this because I want to help those that found this question when they Googled the error. Most other "answers" on the internet were very time consuming. Follow below before you waste so much time like I did.


    What I did was to download JDK 7

    Then change the setting of the jdk to 1.7.0

    enter image description here

    0 讨论(0)
  • 2020-12-02 08:06

    I found Eric and Subin's answers combined solved my problem:

    i.e. need to set the java JDK to Eric's answer (assuming you're using JDK 7):

    /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home.

    The mistake I made was I tried to just select the jdk1.7.0_71.jdk directory and I kept getting the error message "Please choose a valid JDK directory".

    I was working on the format previously used for JDK 6 :( - It worked when I gave it the full path down to into Contents/Home.

    Subin's answer tells you how to find your JDK location which may be different depending on what you're trying to do.

    Thanks Eric and Subin!

    0 讨论(0)
  • 2020-12-02 08:10

    I have been having this problem too. So far I cannot find a fix for it, so I've resorted to changing the maximum SDK version to 20, which works with JDK6.

    As for the file location, instead of Android studio assuming it should be in /System/Library/Java/JavaVirtualMachines/Insert JDK version/Contents/Home.

    In reality my JDK gets installed in /Library/Java/JavaVirtualMachines/JDK Version Here/Contents/Home.

    Trying to select a JDK in the actual directory where its installed makes android studio say that I need to select a valid JDK location. For now I can't find a fix, so like I said above, I have resorted to changing the maximum SDK version to 20 instead of 21 and it will stay like that until more people either suffer from the bug so that Google fix it. Or until an actual fix gets posted online instead of 101 ways for it not to work.

    Hope this helps for now, it isn't really a solution/answer but it is a work around that works for me, for the time being.

    0 讨论(0)
  • 2020-12-02 08:13
    1. Download from here latest JDK.
    2. Open command line tool.
    3. Copy and paste following line into your command line tool and press return.

    /usr/libexec/java_home

    1. Copy output of this command.
    2. Go back to your android project, and navigate as below

    File -> Project structure -> JDK location

    edit(click on square with three dots) JDK location(2nd in image) and paste command line tool output there.

    I have gathered these instructions using MacBook Pro.

    0 讨论(0)
提交回复
热议问题