Java 如何在android studio中指定JDK版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30631286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify the JDK version in android studio?
提问by ThePartyTurtle
Android Studio is giving me a Gradle build error that looks like this:
Android Studio 给了我一个 Gradle 构建错误,如下所示:
Error:(3, 22) compileSdkVersion android-22 requires compiling with JDK 7
Now it gives me these clickable prompts:
现在它给了我这些可点击的提示:
Download JDK 7
Select a JDK from the File System
Open build.gradle File
And I have already downloaded and installed JDK 7. The problem is when I go to select it in the "File System" i can only find a directory named 1.6.0 JDK. Furthermore, the installation of JDK 7 skipped the bullet point where I would've selected the install directory, so I'm really not sure where it is. My java control panel says I have "Java 7 Update 79" so I'm pretty sure I'm close, I just need to tell android studio where it is. I also ran the java -version
command in the terminal and it says my version is "1.7.0_79".
而且我已经下载并安装了JDK 7。问题是当我在“文件系统”中选择它时,我只能找到一个名为1.6.0 JDK的目录。此外,JDK 7 的安装跳过了我选择安装目录的要点,所以我真的不确定它在哪里。我的 java 控制面板说我有“Java 7 Update 79”,所以我很确定我已经接近了,我只需要告诉 android studio 它在哪里。我还在java -version
终端中运行了命令,它说我的版本是“1.7.0_79”。
Any help is appreciated!
任何帮助表示赞赏!
采纳答案by Ben Kane
You can use cmd+ ;for Mac or Ctrl+ Alt+ Shift+ Sfor Windows/Linux to pull up the Project Structure dialog. In there, you can set the JDK location as well as the Android SDK location.
您可以使用cmd+ ;for Mac 或Ctrl+ Alt+ Shift+ Sfor Windows/Linux 来拉出项目结构对话框。在那里,您可以设置 JDK 位置以及 Android SDK 位置。
To get your JDK location, run /usr/libexec/java_home -v 1.7
in terminal. Send 1.7 for Java 7 or 1.8 for Java 8.
要获取您的 JDK 位置,请/usr/libexec/java_home -v 1.7
在终端中运行。为 Java 7 发送 1.7 或为 Java 8 发送 1.8。
回答by Rishabh
For new Android Studio versions, go to C:\Program Files\Android\Android Studio\jre\bin(or to location of Android Studio installed files) and open command window at this location and type in following command in command prompt:-
对于新的 Android Studio 版本,请转到 C:\Program Files\Android\Android Studio\jre\bin(或 Android Studio 安装文件的位置)并在此位置打开命令窗口并在命令提示符下键入以下命令:-
java -version
版本
回答by Lorraine
On a Mac, you can use terminal to go to /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
(or wherever your Android SDK is installed) and enter the following in the command prompt:
在 Mac 上,您可以使用终端转到/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
(或安装 Android SDK 的任何位置)并在命令提示符中输入以下内容:
./java -version
回答by Vishwa Pratap
This is old question but still my answer may help someone
这是一个老问题,但我的回答仍然可以帮助某人
For checking Java version in android studio version , simply open Terminal of Android Studio and type
要在 android studio 版本中检查 Java 版本,只需打开 Android Studio 的终端并输入
java -version
This will display java version installed in android studio
这将显示在 android studio 中安装的 java 版本