So I was migrating an Android Studio project to Java 8, Android API level 24 and the Jack toolchain today to check out the new features, especially lambdas and CompletableFuture
.
Unfortunately, CompletableFuture
seems to be available only from API level 24 on (my minimum API level for that project being 16).
Do you know of any plans on bringing CompletableFuture
to the Android support library? It looks like a nice solution for the Promises pattern.
The streamsupport project provides a backport of CompletableFuture
in its streamsupport-cfuture
component which can be used for Android development, supported on all devices.
Either use
dependencies { implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.4' }
or the more modern android-retrofuture fork for Android Studio >= 3.x
dependencies { implementation 'net.sourceforge.streamsupport:android-retrofuture:1.7.4' }
if you can use Android Studio 3.x and above.
The new Java 12 exception handling methods for CompletableFuture JDK-8211010 have been integrated in release 1.7.0
For users who want a minimal dependency footprint there is also a 105 KiB minifuture
variant which is a "stripped to the bones" version of streamsupport-cfuture
.
dependencies { implementation 'net.sourceforge.streamsupport:streamsupport-minifuture:1.7.4' }
This has no dependencies and provides only the minimum API necessary to use CompletableFuture
and nothing else (no Streams, no public ForkJoinPool and such).
streamsupport
library mentioned in Stefan Zobel's answer was forked especially for Android Studio >=3.0 desugar toolchain, please check android-retrofuture
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With