52

I am new to android development. And I have installed eclipse, java 11 and android sdk tools in my computer. But when I try to build a project it says that to upgrade tools. But I have installed the latest sdk.

When I'm reading in internet I found that android doesn't fully support java SE and it mostly support for java SE 6 and 7. - but this was an old post .

I found that android do not support java 11 completely.

My question is, what is the JDK version that fully support android and do I have to install 2 versions of JDK s in my computer?

9
  • Possible duplicate of Which Java SE versions work with android studio 3.1?
    – ADM
    Nov 24, 2018 at 7:27
  • 4
    Do java 11 support android? Haha. No. Oracle is not Google. Nov 24, 2018 at 7:29
  • 3
    " ... it says that to upgrade tools. " - What exactly did it say. What was the exact message? 'Cos I suspect that it might have been telling you to update the build tools not the Java JDK; see developer.android.com/studio/releases/build-tools
    – Stephen C
    Nov 24, 2018 at 7:48
  • 5
    Also, the original title "Do Java 11 support Android?", it is not necessary for Java 11 to support Android, but possible if Android to support Java 11. So I wonder if it is another X - Y problem.
    – Geno Chen
    Nov 24, 2018 at 8:06
  • 2
    Oracle Java and Openjdk has never supported Android. Android has supported older versions of Java Nov 24, 2018 at 9:50

5 Answers 5

29

With Android Studio Arctic Fox | 2020.3.1 finally you can use Java 11 in your project, here more info: https://developer.android.com/studio/past-releases/past-agp-releases/agp-7-0-0-release-notes#java-11

You can now compile up to Java 11 source code in your app’s project, enabling you to use newer language features like private interface methods, the diamond operator for anonymous classes, and local variable syntax for lambda parameters.

To enable this feature, set compileOptions to the desired Java version and set compileSdkVersion to 30 or above

// build.gradle

android {
    compileSdkVersion 30

    compileOptions {
      sourceCompatibility JavaVersion.VERSION_11
      targetCompatibility JavaVersion.VERSION_11
    }

    // For Kotlin projects
    kotlinOptions {
      jvmTarget = "11"
    }
}
22

May be this 2 articles give more understanding on the situation:

Jake Wharton - Android's Java 9, 10, 11, and 12 Support

Jake Wharton - Android's Java 8 Support

Some features of java 9-12 also supported in Android if you set appropriate compileOptions, for example

compileOptions {
    targetCompatibility JavaVersion.VERSION_12
    sourceCompatibility JavaVersion.VERSION_12
}

P.S. for java 12 you need to set "likely latest" version of Gradle plugin.

1
20

As official doc says:

Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version

so JDK 7 is fully supported, and if you want to use some JDK 8 features, you should Make the appropriate settings.

Here is the ref link for using Java 8

and android studio doesn't support the java version higher than 8.

2
  • So should I use 2 versions of jdks in my computer. And is it possible? Nov 24, 2018 at 7:48
  • Yes it is possible. But it is not clear that it is necessary.
    – Stephen C
    Nov 24, 2018 at 7:55
7

You have the direction of fit backwards. Android supports certain versions of Java, not the other way around.

That being said, Oracle Java and Android Java aren't really the same thing - they don't even use the same virtual machine, as a matter of fact. They're being developed completely separately.

As others have indicated, recent versions of Android supports up to Java 7 and a subset of Java 8 features. Older versions of Android may support less than that.

6

As of 2020 October, A lot of the missing APIs and newer versions of Java are now supported through Open JDK. Some helpful links I find: Support for newer Java language APIs (Official Youtube Video) and Java 8+ APIs available through desugaring. I hope this can help someone struggling with Java versions compatibility

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.