6

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?

Xi Wei
  • 1,669
  • 1
  • 21
  • 33
  • possible duplicate of [Which JDK version (Language Level) is required for Android Studio?](http://stackoverflow.com/questions/17869069/which-jdk-version-language-level-is-required-for-android-studio) – shkschneider May 06 '15 at 15:21

2 Answers2

5

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.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
3

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?

shkschneider
  • 17,833
  • 13
  • 59
  • 112
  • Wait, but I'm confused. Is it Android that needs to support the version of Java or it doesn't matter at all for the Android system and only what matters is what gets there which was converted from whatever language to files that the system understands? Like, if Android Studio supported it, could I use Java 1 on Android 11 and it wouldn't matter? – Edw590 Aug 31 '21 at 22:53