简体   繁体   中英

Does it matter what version of JDK I use in Android Studio?

I know I can choose the SDK location in Android Studio's Project Structure. 项目结构,SDK位置

I have two questions:

  1. Why do we need JDK when we are already using Android SDK? After all, we are not developing for JVM.

  2. Is there any difference between using JDK 1.6, 1.7 and 1.8?

Why do we need JDK when we are already using Android SDK? After all, we are not developing for 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.

Once your code has been compiled, dexed, and packaged into an APK, we need jarsigner to sign the 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?

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.

Android always supported Java 6.

Android now support Java 7 so that is the recommended one (since KitKat).

Android does not support Java 8 as of yet.

You can specify Java 7 like so in your build.gradle file:

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.

EDIT

Actually this was answered here: Which JDK version (Language Level) is required for Android Studio?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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