Search code examples
javaandroidkotlinlintandroid-lint

Lint is giving error if I use java.lang.Iterable#forEach in android code


In my android code (Kotlin) I am using forEach method of java iterable.

mandatoryViews.forEach { view ->
   // my code here
}

Below is my sdk config in build.gradle (app):

minSdkVersion 23
targetSdkVersion 30

Now my code builds fine. I also tried to run it on API 23 pixel device and everything is working fine.

But after I run gradlew lint to see lint errors, it fails and report gives me this error: Call requires API level 24 (current min is 23): java.lang.Iterable#forEach

lint error

Not able to figure why does lint think it will not work on API 23 whereas on API 23 device my code is running fine.


Solution

  • This issue is fixed in lint supplied with Android Gradle plugin 4.2, with 4.2.1 being the latest stable release right now.

    Update your project-level build.gradle to have

    classpath 'com.android.tools.build:gradle:4.2.1'
    

    in its buildscript.dependencies block.