Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Java 8 for Android development?

Searching the web, it is not clear if Java 8 is supported for Android development or not.

Before I download/setup Java 8, can some one point me at any "official" documentation that says Java 8 is or is not supported for Android development.

like image 777
nPn Avatar asked Apr 27 '14 00:04

nPn


People also ask

Can I use Java 8 for Android?

Java 8 has been supported natively since Android SDK 26. If you wish to use Java 8 language features and your minimal SDK version is lower than 26, . class files produced by the javac compiler need to be converted to bytecode that is supported by these SDK versions.

Which version of Java is used for Android?

Class libraryJava 8 source code that works in latest version of Android, can be made to work in older versions of Android.

Can Android use Java 11?

Android SDK tools are not yet compatible with Java 11 and need Java 8 (1.8) to run correctly. The Bitrise stacks provide both Java 8 and Java 11, with Java 8 being active by default. If you need a Java 11 runtime for your project to compile, you can switch to Java 11 only before it's needed by the next Step.

Which Java version is best for Android Studio?

A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects.


2 Answers

UPDATE 2017/11/04 - Android Studio 3.0 now has native support for Java 8. gradle-retrolambda is now no longer needed. See https://developer.android.com/studio/write/java8-support.html

The above link also includes migration instructions if you are using gradle-retrolambda. Original answer below:


Android does not support Java 8. It only supports up to Java 7 (if you have kitkat) and still it doesn't have invokedynamic, only the new syntax sugar.

If you want to use lambdas, one of the major features of Java 8 in Android, you can use gradle-retrolamba. It's a gradle build dependency that integrates retrolambda, a tool that converts Java 8 bytecode back to Java 6/7. Basically, if you set the compiler in Android Studio to compile Java 8 bytecode, thus allowing lambdas, it'll convert it back to Java 6/7 bytecode which then in turn gets converted to dalvik bytecode. It's a hack for if you want to try out some JDK 8 features in Android in lieu of official support.

like image 147
ekcr1 Avatar answered Sep 21 '22 03:09

ekcr1


java 8

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

To check which features of java 8 are supported

Use Java 8 language features

We've decided to add support for Java 8 language features directly into the current javac and dx set of tools, and deprecate the Jack toolchain. With this new direction, existing tools and plugins dependent on the Java class file format should continue to work. Moving forward, Java 8 language features will be natively supported by the Android build system. We're aiming to launch this as part of Android Studio in the coming weeks, and we wanted to share this decision early with you.

Future of Java 8 Language Feature Support on Android

Eclipse Users:

For old developers who prefer Eclipse, google stops support Eclipse Android Developer tools

if you installed Java 8 JDK, then give it a try, if any problems appears try to set the compiler as 1.6 in Eclipse from window menu → PreferencesJavaCompiler. Java 7 will works too:

Eclipse Preferences -> Java -> Compiler

Java 7 or higher is required if you are targeting Android 5.0 and higher.

install multiple JDK and try.

like image 43
Eng. Samer T Avatar answered Sep 21 '22 03:09

Eng. Samer T