Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Why Apache Harmony" or "How to use Java 8 on Android"

Most of us have heard by now of the cool features Java 8 will bring, but Android will not support it. This is because of Google using Apache Harmony for Android. This is what is keeping us (the android app developers) from improving our code with lambdas, default implementations in interfaces, switching on a String and a lot more. Surely, we will handle for some time, but what if some libraries we use in our apps start to use Java 8 features? As far as I know, this will not work (please correct me if wrong). This creates incompatibility between Standard-Java and Android-Java. It cannot be what Google intends, or at least I can't think of a reason why a company, developing a widely adopted operating system, would wan't to permanently stay with an old Java version.

Questions:

  • Why do they use Apache Harmony?
  • Why can't they adopt a newer version of java?
  • If they don't want Oracle's Java, why can't they use a subset of OpenJDK (licensing noob here)?
  • Do you know of any plans to update the used Java version?
  • Do you know of any way to use Java 8 classes on current Android systems?
like image 645
tilpner Avatar asked Jun 04 '13 15:06

tilpner


People also ask

Can I use Java 8 for Android?

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.

Is Java compatible with Android?

Current versions of Android use the latest Java language and its libraries (but not full graphical user interface (GUI) frameworks), not the Apache Harmony Java implementation, that older versions used. Java 8 source code that works in latest version of Android, can be made to work in older versions of Android.


1 Answers

Why do they use Apache Harmony?

Because Sun refused to provide Google with a license for Sun (now Oracle) Java under terms that were acceptable. Google and Sun negotiated, but they ended up walking away from the deal.

Nitpick: in fact, the Android libraries are not Apache Harmony. They started out as based on Harmony, but the two codebases have diverged. Furthermore, the Apache Harmony project was officially "retired" in November 2011.

Why can't they adopt a newer version of java?

Firstly, Android does not run Java(tm). It runs a language that is identical to Java with a class library that is functionally equivalent to a subset of the Java class library (+ Android-specific libraries), on a virtual machine with a different instruction set.

From a technical pespective, they could ... but only if they put in a lot of work into implementing Java 7 and Java 8 language features, library features, etc, for the Android platform.

UPDATE - As of Android 19 (KitKat) and Eclipse ADT 22.6, Android does now support the Java 7 language extensions; see http://tools.android.com/recent/eclipseadt226preview

If they don't want Oracle's Java, why can't they use a subset of OpenJDK?

I don't think that switching to OpenJDK would change anything. Oracle Java and OpenJDK are 99.9% the same.

Anyway, there may be licensing and related legal issues. (And to get a feel for that, read up on the Oracle vs Google lawsuit ... that is going to appeal.)

More likely, Google doesn't see enough commercial value to counteract the (massive) effort it would take to change, and the disruption it would cause to the Android ecosystem ... which already suffers from problems with fragmentation.

Do you know of any plans to update the used Java version?

No I don't. It doesn't mean that there aren't plans, but if there are, they are not public.

Do you know of any way to use Java 8 classes on current Android systems?

You could port them. Or at least, you could try to port them. (Some Java APIs have an intimate relationship with the native code side of the JVM ... and that could make porting problematic.)

like image 162
Stephen C Avatar answered Oct 06 '22 23:10

Stephen C