简体   繁体   English

错误:compileSdkVersion android-21需要使用JDK 7进行编译

[英]Error:compileSdkVersion android-21 requires compiling with JDK 7

While compiling i get the error Error:compileSdkVersion android-21 requires compiling with JDK 7 , saying that a newer version of JDK is required. 编译时我得到错误Error:compileSdkVersion android-21 requires compiling with JDK 7 ,说需要更新版本的JDK。

I'm running on OS X Yosemite with Android Studio v0.8.14 我正在使用Android Studio v0.8.14在OS X Yosemite上运行

Things I checked : 我查过的东西:

  1. Java version : Java版本:

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. 在JavaVirtualMachine文件夹里面我只能看到1.6.0.jdk文件夹,我找不到任何其他文件夹。

  2. Tried reinstalling JDk 8 and 7! 尝试重新安装JDk 8和7!

I'm unable to find the folder location of jvm 1.8, any idea how I can fix there. 我无法找到jvm 1.8的文件夹位置,任何想法我怎么能在那里修复。

The Exact Fix for this Issue (Android Studio Users on Mac) 针对此问题的精确修复(Mac上的Android Studio用户)

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 . 如果您已经升级到Java 8,请注意JDK位置现在位于/Library/Java与Java 6的位置/System/Library/Java So to fix this problem, Right click on the Project folder > Project Structure > SDK Location. 因此,要解决此问题,请右键单击“ 项目”文件夹 >“ 项目结构” >“ SDK位置”。

Then change JDK location to 然后将JDK位置更改为

/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. 如果您安装了不同的JDK版本(Java 8除外),请首先使用java_home脚本查找路径并使用输出。 Just run, 赶紧跑,

/usr/libexec/java_home 

Actually I just found the solution - JDK 7 is in /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home. 其实我刚刚找到解决方案 - JDK 7在/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home中。

that got it working for me. 让它为我工作。 Oracle Docs on where JDK7 is installed 安装JDK7的Oracle Docs

I got a solution. 我有一个解决方案。 It happened with me too and I searched a lot on Google but all I got was hints. 它也发生在我身上,我在Google上搜索了很多,但我得到的只是提示。 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. 这是因为计算机没有安装JDK 7(或更高版本)。 The JDK directory in AS/Configuration might points to JDK6. AS / Configuration中的JDK目录可能指向JDK6。 (That System/Library/...) (那个系统/图书馆/ ......)

All you need to do is: 你需要做的就是:

  1. Download latest JDK. 下载最新的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 将Android Studio /配置/项目默认值/项目结构/(JDK位置:)指向/ 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. 花了一整天搞乱gradle,android studio。 Happy coding. 快乐的编码。

I found Eric and Subin's answers combined solved my problem: 我发现Eric和Subin的答案结合起来解决了我的问题:

ie need to set the java JDK to Eric's answer (assuming you're using JDK 7): 即需要将java JDK设置为Eric的答案(假设您使用的是JDK 7):

/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home. /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". 我犯的错误是我试图选择jdk1.7.0_71.jdk目录并且我不断收到错误消息“请选择一个有效的JDK目录”。

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. 我正在研究以前用于JDK 6的格式:( - 当我把它完整的路径下载到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. Subin的答案告诉您如何找到您的JDK位置,这可能会因您尝试的操作而有所不同。

Thanks Eric and Subin! 谢谢Eric和Subin!

I am sharing this because I want to help those that found this question when they Googled the error. 我正在分享这个,因为我想帮助那些在Google搜索错误时发现这个问题的人。 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 我做的是下载JDK 7

Then change the setting of the jdk to 1.7.0 然后将jdk的设置更改为1.7.0

在此输入图像描述

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. 到目前为止,我找不到它的修复,所以我已经使用最大的SDK版本更改为20,这适用于JDK6。

As for the file location, instead of Android studio assuming it should be in /System/Library/Java/JavaVirtualMachines/ Insert JDK version /Contents/Home. 至于文件位置,而不是Android工作室假设它应该在/ System / Library / Java / JavaVirtualMachines / Insert JDK version / Contents / Home中。

In reality my JDK gets installed in /Library/Java/JavaVirtualMachines/ JDK Version Here /Contents/Home. 实际上我的JDK安装在/ 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. 试图在安装它的实际目录中选择一个JDK使android studio说我需要选择一个有效的JDK位置。 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. 现在我找不到修复,所以就像我上面所说的那样,我已经将最大的SDK版本更改为20而不是21,并且它将保持这样,直到更多的人要么遇到这个bug,以便Google修复它。 Or until an actual fix gets posted online instead of 101 ways for it not to work. 或者直到实际修复在线发布而不是101种方式才能使其无法正常工作。

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. 希望这对现在有帮助,它不是一个真正的解决方案/答案,但它是一个适合我的工作,暂时。

if you only have folder 1.6.0.jdk then go to this link and download and install jdk 1.7. 如果您只有文件夹1.6.0.jdk,那么请转到此链接并下载并安装jdk 1.7。 then find your java folder in this path 然后在此路径中找到您的java文件夹

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

The solutions on this thread are not valid for the same error in Android Studio 1.4 . 此线程上的解决方案对于Android Studio 1.4中的相同错误无效。 The preferences menu, for example, is gone. 例如,首选项菜单已消失。 Below is the solution for Android Studio 1.4 running on Ubuntu 14.04. 以下是在Ubuntu 14.04上运行的Android Studio 1.4的解决方案。

To solve in Ubuntu 14.04+ and Android Studio 1.4+, you need to go to 要在Ubuntu 14.04+和Android Studio 1.4+中解决,您需要转到

File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project Bytecode Version 文件 - >其他设置 - >默认设置 - >构建,执行,部署 - >编译器 - > Java编译器 - >项目字节码版本

This drop-down will be empty by default. 默认情况下,此下拉列表将为空。

Set to your preferred JDK, in the case of the screencap below, 1.8 . 设置为首选JDK,对于下面的屏幕截图,为1.8。

android sdk screencap

Voila, your project will compile. 瞧,你的项目将编译。

  1. Download from here latest JDK. 从这里下载最新的JDK。
  2. Open command line tool. 打开命令行工具。
  3. Copy and paste following line into your command line tool and press return. 将以下行复制并粘贴到命令行工具中,然后按Return键。

/usr/libexec/java_home 的/ usr /的libexec / JAVA_HOME

  1. Copy output of this command. 复制此命令的输出。
  2. Go back to your android project, and navigate as below 回到你的android项目,然后导航如下

File -> Project structure -> JDK location 文件 - >项目结构 - > JDK位置

edit(click on square with three dots) JDK location(2nd in image) and paste command line tool output there. 编辑(点击带有三个点的正方形)JDK位置(图像中的第2个)并在那里粘贴命令行工具输出。

在此输入图像描述 I have gathered these instructions using MacBook Pro. 我已经使用MacBook Pro收集了这些说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM