简体   繁体   中英

Error: Call requires API level 24 (current min is 21): java.util.Map#forEach [NewApi]

I have two enum class EventKey and EventProperty

enum class EventKey(val firebaseKey: String? = null) {
       SIGNIN(firebaseKey = "singin"),
       .....
}

enum class EventProperty(val property: String) {
    TYPE1("type1"),
    ....
}

I am getting error on this

fun event(eventKey: EventKey, properties: Map<EventProperty, Any>) {
        eventKey.firebaseKey?.let { key ->
            properties?.forEach { entry ->
                eventData.put(entry.key.property, entry.value)
            }
        }
}

I tried this Kotlin Extension Functions suddenly require api level 24 , Lint considers Kotlin MutableMap.forEach() as java.util.Map.forEach() and change the code

properties?.forEach { (entry) ->
     eventData.put(entry.property, entry)
}

or

properties?.forEach { (entry,value) ->
     eventData.put(entry.property, value)
 }

It giving the same error on lint checking, also what i am doing in code after changing the stack overflow answer.

Using Kotlin 1.5.20

I run into this by bump Kotlin from 1.7.22 to 1.8.0

Error: Call requires API level 24 (current min is 21): java.lang.Iterable#forEach [NewApi]
            allArrived(clientHandle).forEach {
                                     ~~~~~~~

My solution

I bumped from

com.android.tools.build.gradle:7.3.1 to

com.android.tools.build.gradle:7.4.0 and now it's working for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM