Cannot use lambda functions in Android with Java 1.8

前端 未结 3 1562
情书的邮戳
情书的邮戳 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: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
    }
    

提交回复
热议问题