Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Project Structure, SDK Location

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?

like image 241
Xi Wei Avatar asked May 06 '15 15:05

Xi Wei


2 Answers

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.

like image 81
Bryan Herbst Avatar answered Sep 23 '22 06:09

Bryan Herbst


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?

like image 34
shkschneider Avatar answered Sep 22 '22 06:09

shkschneider