11

According to Google's introduction, starting with Android N, the Android API is supposed to support Java streams.

However, using the Android N preview SDK, I am unable to use any of the Stream APIs in my project (which is configured with Android N as minimum, target and build SDK version).

The java.util.stream package seems to be missing, as are the stream() methods of all collection implementations I've tried.

Are the necessary classes not yet included in the current preview release of the SDK?

lxgr
  • 3,719
  • 7
  • 31
  • 46
  • http://stackoverflow.com/questions/36000997/android-n-java8-java-time All features of Java 8 are not supported there are some of the features are only supported in preview. – Maheshwar Ligade Mar 20 '16 at 09:32
  • So the Android developers blog post is incorrect? It explicitly states that "default and static methods, streams, and functional interfaces -- are also now available on N and above". – lxgr Mar 20 '16 at 09:33
  • http://developer.android.com/intl/zh-cn/preview/j8-jack.html this is as per the developer document. – Maheshwar Ligade Mar 20 '16 at 09:38
  • The stream API is not a Java 8 language feature (which are implemented by the new Jack compiler and available to earlier Android targets). It would be provided as a set of interfaces and implementation classes in the Android SDK. – lxgr Mar 20 '16 at 09:45
  • `java.util.stream` also does not appear in the offline JavaDocs for the N Developer Preview 1. Between that and your experiences, it would appear that `java.util.stream` did not "make the cut". Whether this is a bug in the description or a bug in the SDK proper is unclear to me. – CommonsWare Mar 20 '16 at 10:51
  • The "Java 8" support is not part of Android N - it will be supported with all versions starting from Gingerbread. Apparently this would be a feature of a new Jack compiler. So, until Jack compiler is released I would not expect anything. – Dmitry Zaytsev Mar 22 '16 at 14:03
  • 1
    Please distinguish between Java language, bytecode and library features. Jack (which is already available and works fine, by the way), for example, compiles Lambdas in a way that is backwards-compatible with older versions of Dalvik. (The "real" JDK, for comparison, implements them using Java 7 bytecode features – invokedynamic – and Java 8 classes – LambdaMetafactory.) Streams, on the other hand, are a library feature even on android, and will only be available to N+. – lxgr Mar 22 '16 at 14:12
  • Oh, I see - perhaps I was expecting too much magic from Jack. Something like packing those libraries into the app. – Dmitry Zaytsev Mar 22 '16 at 14:29

1 Answers1

13

It's not yet in the current preview, but it has already been merged into the AOSP Git master. See here https://android.googlesource.com/platform/libcore/+/916b0af2ccdd1bdfc0283b1096b291c40997d05f

EDIT:

Just to avoid possible confusion: in March 2016, when this question has been asked by the OP, Android N developer preview-1 was the only publicly available build of what is now known as Android 7.0 "Nougat".

The preview-1 build did in fact not include the Java 8 Stream API, but it was added shortly after (one month later) in the developer preview-2 build.

So, Android 7.0 API level 24 does support the Java 8 Stream API now.

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
  • Please update your answer - Stream API is included in latest revision of Android 7.0 SDK Platform (API 24). – Alex Lipov Jul 30 '16 at 11:28