I know I can choose the SDK location in Android Studio's Project Structure.
我知道我可以在Android Studio的项目结构中选择SDK位置。
I have two questions:
我有两个问题:
-
Why do we need JDK when we are already using Android SDK? After all, we are not developing for JVM.
当我们使用Android SDK时,为什么还需要JDK?毕竟,我们不是为JVM开发的。
-
Is there any difference between using JDK 1.6, 1.7 and 1.8?
使用JDK 1.6,1.7和1.8之间有什么区别吗?
2 个解决方案
#1
Why do we need JDK when we are already using Android SDK? After all, we are not developing for JVM.
当我们使用Android SDK时,为什么还需要JDK?毕竟,我们不是为JVM开发的。
The Android build process depends on a number of tools from the JDK. Check out the build system overview documentation. The first big piece we need from JDK is javac
- all your source code written in Java needs to be compiled before it can be converted to the DEX foramt.
Android构建过程依赖于JDK中的许多工具。查看构建系统概述文档。我们需要JDK的第一个重要部分是javac-所有用Java编写的源代码都需要在转换为DEX foramt之前进行编译。
Once your code has been compiled, dexed, and packaged into an APK, we need jarsigner
to sign the APK.
一旦您的代码被编译,dexed并打包到APK中,我们需要jarsigner来签署APK。
Is there any difference between using JDK 1.6, 1.7 and 1.8? That depends on what features you are using from each. Older projects that don't use Java 7 features can use Java 6 without issue. I personally recommend Java 7 for most modern projects. If you can use it, why not?
使用JDK 1.6,1.7和1.8之间有什么区别吗?这取决于您使用的功能。不使用Java 7功能的旧项目可以毫无问题地使用Java 6。我个人推荐Java 7用于大多数现代项目。如果你可以使用它,为什么不呢?
There are some efforts out there to bring Java 8 features to Android, most notably gradle-retrolambda. Some of these require JDK 8 to compile properly.
有一些努力将Java 8功能引入Android,最着名的是gradle-retrolambda。其中一些需要JDK 8才能正确编译。
#2
Android always supported Java 6.
Android始终支持Java 6。
Android now support Java 7 so that is the recommended one (since KitKat).
Android现在支持Java 7,因此推荐使用它(自KitKat以来)。
Android does not support Java 8 as of yet.
Android目前还不支持Java 8。
You can specify Java 7 like so in your build.gradle file:
您可以在build.gradle文件中指定Java 7:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
The only difference being the Java version (Java 7 adds features of course) and the fact that Android does not support Java 8 period.
唯一的区别是Java版本(Java 7当然增加了功能)以及Android不支持Java 8时期的事实。
EDIT
Actually this was answered here: Which JDK version (Language Level) is required for Android Studio?
实际上这在这里得到了回答:Android Studio需要哪个JDK版本(语言级别)?
#1
Why do we need JDK when we are already using Android SDK? After all, we are not developing for JVM.
当我们使用Android SDK时,为什么还需要JDK?毕竟,我们不是为JVM开发的。
The Android build process depends on a number of tools from the JDK. Check out the build system overview documentation. The first big piece we need from JDK is javac
- all your source code written in Java needs to be compiled before it can be converted to the DEX foramt.
Android构建过程依赖于JDK中的许多工具。查看构建系统概述文档。我们需要JDK的第一个重要部分是javac-所有用Java编写的源代码都需要在转换为DEX foramt之前进行编译。
Once your code has been compiled, dexed, and packaged into an APK, we need jarsigner
to sign the APK.
一旦您的代码被编译,dexed并打包到APK中,我们需要jarsigner来签署APK。
Is there any difference between using JDK 1.6, 1.7 and 1.8? That depends on what features you are using from each. Older projects that don't use Java 7 features can use Java 6 without issue. I personally recommend Java 7 for most modern projects. If you can use it, why not?
使用JDK 1.6,1.7和1.8之间有什么区别吗?这取决于您使用的功能。不使用Java 7功能的旧项目可以毫无问题地使用Java 6。我个人推荐Java 7用于大多数现代项目。如果你可以使用它,为什么不呢?
There are some efforts out there to bring Java 8 features to Android, most notably gradle-retrolambda. Some of these require JDK 8 to compile properly.
有一些努力将Java 8功能引入Android,最着名的是gradle-retrolambda。其中一些需要JDK 8才能正确编译。
#2
Android always supported Java 6.
Android始终支持Java 6。
Android now support Java 7 so that is the recommended one (since KitKat).
Android现在支持Java 7,因此推荐使用它(自KitKat以来)。
Android does not support Java 8 as of yet.
Android目前还不支持Java 8。
You can specify Java 7 like so in your build.gradle file:
您可以在build.gradle文件中指定Java 7:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
The only difference being the Java version (Java 7 adds features of course) and the fact that Android does not support Java 8 period.
唯一的区别是Java版本(Java 7当然增加了功能)以及Android不支持Java 8时期的事实。
EDIT
Actually this was answered here: Which JDK version (Language Level) is required for Android Studio?
实际上这在这里得到了回答:Android Studio需要哪个JDK版本(语言级别)?