使用 Android Studio 需要 Java JDK 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42172010/
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
Do I need Java JDK for using Android Studio?
提问by Mindril
I'm learning Android Studio and the tutorials on youtube like:
我正在学习 Android Studio 和 youtube 上的教程,例如:
https://www.youtube.com/watch?v=QAbQgLGKd3Y&list=PL6gx4Cwl9DGBsvRxJJOzG4r4k_zLKrnxl
https://www.youtube.com/watch?v=QAbQgLGKd3Y&list=PL6gx4Cwl9DGBsvRxJJOzG4r4k_zLKrnxl
say I need the Java JDK.
说我需要 Java JDK。
Yet when I went through the tutorial at the website:
然而,当我浏览网站上的教程时:
https://developer.android.com/training/basics/firstapp/creating-project.html
https://developer.android.com/training/basics/firstapp/creating-project.html
I was able to setup and run the myfirstapp project.
我能够设置和运行 myfirstapp 项目。
Does the new AS include the SDK or will I need it for more complicated projects.
I guess I can just run through the video tutorial until I encounter a problem but I'd like to know before I have to uninstall Android Studio, install the JDK and reinstall Android Studio.
新 AS 是否包含 SDK,或者我是否需要它用于更复杂的项目。
我想我可以只看视频教程直到遇到问题,但我想知道在我必须卸载 Android Studio、安装 JDK 并重新安装 Android Studio 之前。
Seems a real pain.
看起来真的很痛苦。
采纳答案by OneCricketeer
Android Studio version 2.2 and higher comes with the latest OpenJDK embedded in order to have a low barrier to entry for beginners.
Android Studio 2.2 及更高版本嵌入了最新的 OpenJDK,以降低初学者的入门门槛。
It is, however, recommended to have the JDK installed on your own as you are then able to update it independent of Android Studio.
但是,建议您自己安装 JDK,因为这样您就可以独立于 Android Studio 更新它。
If you are working with an Android API < 24, then you'll need to compile the project with Java 7 or do some extra steps to enable Java 8 features. (Note: Java 8 support is relatively new).
如果您使用的是 Android API < 24,那么您需要使用 Java 7 编译项目或执行一些额外的步骤来启用 Java 8 功能。(注意:Java 8 支持相对较新)。
Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features
Android Studio 3.0 及更高版本支持所有 Java 7 语言功能和一部分 Java 8 语言功能
回答by SomeAndroidDeveloper
This is what Google says on https://developer.android.com/studio/intro/studio-config.html:
这是谷歌在https://developer.android.com/studio/intro/studio-config.html 上所说的:
A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects.
最新的 OpenJDK 副本与 Android Studio 2.2 及更高版本捆绑在一起,这是我们建议您用于 Android 项目的 JDK 版本。
So if you are using the newest version, you won't need any additional JDK. Furthermore, the official installation instructions don't include anymore any hints towards the JDK, compared to June 2016.
因此,如果您使用的是最新版本,则不需要任何额外的 JDK。此外,与2016 年 6 月相比,官方安装说明不再包含任何关于 JDK 的提示。
回答by Code Freeze
On the Mac, the path for Android Studio's Java environment can be set with this export command:
在 Mac 上,可以使用以下导出命令设置 Android Studio 的 Java 环境的路径:
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/
导出 JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/
This uses the JAVA (OpenJDK) that comes with Android Studio.
这使用了 Android Studio 附带的 JAVA (OpenJDK)。
回答by Isaac Rabinovitch
You usedto need to install a JDK; hence the videos telling you how to do it. Recent versions include a built-in JDK. Note that Android Studio has evolved rapidly, and tutorials quickly become obsolete.
您使用需要安装一个JDK; 因此,视频会告诉您如何操作。最近的版本包括一个内置的 JDK。请注意,Android Studio 发展迅速,教程很快就会过时。
Note that installing Android Studio doesn't automatically configure the built-in JDK command line tools. This matters if you want to use the Android SDK command line tools. To fix this, find the bin
directory within the Android Studio installation that contains the java
command (the native command that actually runs the Java Virtual Machine), and add it to your path. (Another thing that might change, so I won't add specific directories to this answer.) This file is java.exe
on Windows; on every other platform it's called java
and has executable permission.
请注意,安装 Android Studio 不会自动配置内置的 JDK 命令行工具。如果您想使用 Android SDK 命令行工具,这很重要。要解决此问题,请bin
在 Android Studio 安装中找到包含该java
命令(实际运行 Java 虚拟机的本机命令)的目录,并将其添加到您的路径中。(另一件事可能会改变,所以我不会在这个答案中添加特定的目录。)这个文件java.exe
在 Windows 上;在其他所有平台上,它都被调用java
并具有可执行权限。
(You'll also need to add the directories containing the SDK tools themselves.)
(您还需要添加包含 SDK 工具本身的目录。)
There are actually two such directories, because the JDK, like all Java applications, contains a Java Runtime Environment (JRE). If you just want to run the SDK tools, then it doesn't matter which bin
directory you choose. But if you want to compile and run Java code outside Android Studio, then you need to use the bin
containing the javac
command, among other essential JDK development tools.
实际上有两个这样的目录,因为与所有 Java 应用程序一样,JDK 包含一个 Java 运行时环境 (JRE)。如果您只是想运行 SDK 工具,那么bin
您选择哪个目录都没有关系。但是如果你想在 Android Studio 之外编译和运行 Java 代码,那么你需要使用bin
包含该javac
命令的命令,以及其他必不可少的 JDK 开发工具。
Or you can just install the latest JDK. No real reason not to.
或者您可以只安装最新的 JDK。没有真正的理由不这样做。