Cannot use lambda functions in Android with Java 1.8

前端 未结 3 1540
情书的邮戳
情书的邮戳 2021-01-02 21:40

The library I\'m using is bychan, I can\'t even include it in a Nougat empty app project either loaded as module or through jar.

So this is an examp

相关标签:
3条回答
  • 2021-01-02 22:33

    Overall set up looks good to me except for the Java JDK 1.8 part.You need to set a correct path to JDK installation folder in Android Studio in order to use all the new Java 8 features.

    0 讨论(0)
  • 2021-01-02 22:34

    Android SDK < 24 does not support java.util.function.Function and java.util.function.Predicate interfaces because Java 8 allows functional interfaces to contain default methods which is only supported in SDK 24 and above. I had this problem when I was using consumers, and the way I fixed it was to create my own clown of java.util.function.Consumer interface without all the default methods. You can also fix this issue by increasing the minimum SDK of your app to 24.

    Update

    Add the following to your build.gradle file

    defaultConfig {
    
      jackOptions {
        enabled true
      }
    }
    compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
    }
    
    0 讨论(0)
  • 2021-01-02 22:38

    I would not suggest to use java 8. It is not supported nowadays. But, even, it will: remember, that each devices has got its own java machine that will not update. I mean, if you wanna be sure your app works properly setup your project as java 6. Old devices this never support up-to-date JMV

    Read this discussion too

    Which JDK version (Language Level) is required for Android Studio?

    0 讨论(0)
提交回复
热议问题