I am using Java JDK version 1.8.0_60-b27 for both Netbeans and Android Studio. I could not import java.util.function.Consumer and java.util.stream.Stream packages in my Android Studio project. But I can import the same in my Netbeans Project. What is the reason?
In Google I/O 2016, they announced that Android now supports some features of Java 8, but not all the features.
Features like : - Default and static interface methods - Lambda expressions (also available on API level 23 and lower) - Repeatable annotations - Method References (also available on API level 23 and lower) - Type Annotations (also available on API level 23 and lower)
Additionally, the following Java 8 language APIs are also available:
Reflection and language-related APIs: java.lang.FunctionalInterface java.lang.annotation.Repeatable java.lang.reflect.Method.isDefault() and Reflection APIs associated with repeatable annotations, such as AnnotatedElement.getAnnotationsByType(Class) Utility APIs: java.util.function java.util.stream
All what you should do is to use the new jack compiler, to do this you have just to add this to your gradle file build.gradle "module:app":
android {
...
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Refrences https://developer.android.com/guide/platform/j8-jack.html https://www.youtube.com/watch?v=B08iLAtS3AQ&feature=youtu.be&t=28m14s
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