Is Android N Stream API backported to lower versions?

情到浓时终转凉″ 提交于 2019-12-10 16:08:49

问题


Latest version of Android N has stream package but when i'm trying to use it is saying min Sdk version which i should use is 24 (N) and my min SDK is 16.

I enabled JackOptions with which Lambda expressions , Method References are working fine ( even for versions less than N minsdk) but still has problem is only with Stream package . The link below https://developer.android.com/guide/platform/j8-jack.html says lambda, method references are available to 23 n lower also but no clarity on Stream package.

So i want to understand that Steam package i cannot use in my project ( minsdk 16) ? Or am I missing something .

All sdk components are updated . compileSdkVersion 24 buildToolsVersion "24.0.2" minSdkVersion 16 targetSdkVersion 24 (23 doesn't matter )

Please suggest me what i should do . Also i saw streamsupport https://github.com/streamsupport/streamsupport which is working fine but i don't want to add a new dependency.


回答1:


Is Android N Stream API backported to lower versions?

No, it is not, at least in terms of literally using java and javax packages, such as java.util.stream. No classes get backported to their original Java packages, as otherwise there are namespace collisions on newer devices.

To date, Google has not released some sort of workalike classes for java.util.stream, etc., as a library, where those classes happen to use a separate Java package.




回答2:


Unfortunately Google has not backported the Java 8 streams API to lower API versions. This means there currently is no AppCompatStream or anything of that sort.
However, It is possible to use Java 8 Stream API on Android minSdkVersion < 24 if you are willing to use 3rd party libraries in your project. Here are several such open source projects (shout out to this post):

Lightweight Stream API

Solid

StreamSupport

If you aren't interested in adding another gradle dependency, there is always the possibility of adding the whole project as another module in your Android Studio project, or even as another package in your app's module.



来源:https://stackoverflow.com/questions/39265004/is-android-n-stream-api-backported-to-lower-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!