Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error importing java.util.stream.Stream in Android Studio

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?

like image 947
Vignesh Avatar asked Jan 27 '26 00:01

Vignesh


1 Answers

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

like image 105
Zeyad Assem Avatar answered Jan 28 '26 12:01

Zeyad Assem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!