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?

Seniru Pasan
  • 753
  • 1
  • 7
  • 13
  • Possible duplicate of [Which Java SE versions work with android studio 3.1?](https://stackoverflow.com/questions/49788102/which-java-se-versions-work-with-android-studio-3-1) – ADM Nov 24 '18 at 07:27
  • 4
    *Do java 11 support android?* Haha. **No**. Oracle is not Google. – Elliott Frisch Nov 24 '18 at 07: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 https://developer.android.com/studio/releases/build-tools – Stephen C Nov 24 '18 at 07:48
  • Any screenshot or hint for the **detailed message** of "upgrade tools"? Since you are using Eclipse, I wonder if you are using an out-dated ADT. – Geno Chen Nov 24 '18 at 08:03
  • 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 '18 at 08:06
  • 2
    Oracle Java and Openjdk has never supported Android. Android has supported older versions of Java – Peter Lawrey Nov 24 '18 at 09:50
  • You will be able to use it approximately +10 years from now. – Vahid Amiri Jan 09 '19 at 06:17
  • Yes, it's supported now. I've found it from @mycky's answer here. Here is the link - https://developer.android.com/studio/releases/gradle-plugin?utm_source=android-studio-2020-3-1&utm_medium=studio-assistant-stable#java-11 – Md. Nowshad Hasan Sep 24 '21 at 14:32
  • Quick note: I know that this is a somewhat old post, but while the most recent edit was technically "correct" , it also partially invalidates an existing answer (so I rolled back). – EJoshuaS - Stand with Ukraine Sep 27 '21 at 16:20

5 Answers5

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"
    }
}
Adam Burley
  • 5,551
  • 4
  • 51
  • 72
mycky
  • 628
  • 10
  • 16
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.

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
Mike
  • 479
  • 5
  • 15
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.

navylover
  • 12,383
  • 5
  • 28
  • 41
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

ddsultan
  • 2,027
  • 1
  • 19
  • 19