Status Update
Comments
ky...@gmail.com <ky...@gmail.com> #2
I have also been using this for years and when updating to support SDK 35 it says it is not available on older versions. For now, I switched to MutableList.removeAt(0) since that works still.
lb...@gmail.com <lb...@gmail.com> #3
@2 Thing is, I tested it when it's targeting API 35, and it still works fine on API 34...
I think it's false positive.
vi...@google.com <vi...@google.com> #4
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
vi...@google.com <vi...@google.com> #5
java.util.ArrayList#removeFirst()
API was introduced in API 35.
Unfortunately, it's a known issue due to collision with the MutableList.removeLast()
in the the Kotlin std library
According to Kotlin spec,
If a class has a member function, and an extension function is defined which has the same receiver type, the same name, and is applicable to given arguments, the member always wins.
We are working the internal team to resolve this API issue with Kotlin standard library.
vi...@google.com <vi...@google.com> #6
Unfortunately, it's a known issue due to collision with the MutableList.removeLast() in the the Kotlin std library
Sorry, I meant MutableList.removeFirst()
lb...@gmail.com <lb...@gmail.com> #7
@5 But why was it added only recently, why the warning when it works fine, and what should we use instead?
Isn't it the same as removeAt(0)
?
@6 You can edit your comments, as you are a part of Google...
ab...@gmail.com <ab...@gmail.com> #8
lb...@gmail.com <lb...@gmail.com> #9
@8 It can cause a crash?
Is it possible you use Java and not Kotlin?
It's just that I tried it and despite the warning, it worked fine on Android 14...
Can you make a POC and publish here?
vi...@google.com <vi...@google.com> #10
removeFirstOrNull()
and removeAt(0)
are both reasonable alternatives right now. It doesn't cause a crash when the method is invoked on Android 14 if the list isn't empty.
They have different behaviors when the list is empty though.
lb...@gmail.com <lb...@gmail.com> #11
@10 That's weird.
What's the different behavior between removeAt(0)
and removeFirst
, whether the list is empty or not?
Why didn't you mention it?
vi...@google.com <vi...@google.com> #12
Hi, Just want to update the information here after discussing with other teams internally.
For the collision with MutableList.removeFirst()
and MutableList.removeLast()
extension functions in kotlin-stdlib
The List
type in java is mapped to the MutableList
type in Kotlin. Because the List.removeFirst()
and List.removeLast()
APIs have been introduced in Android 15 (API level 35), the Kotlin compiler resolves function calls, for example list.removeFirst(), statically to the new List APIs instead of to the extension functions in kotlin-stdlib.
If an app is re-compiled with compileSdk
set to 35 and minSdk
set to 34 or lower, and then the app is run on Android 14 and lower, a runtime error is thrown:
java.lang.NoSuchMethodError: No virtual method removeFirst()Ljava/lang/Object; in class Ljava/util/ArrayList;
The existing NewApi lint option in Android Gradle Plugin can catch these new API usages.
./gradlew lint
MainActivity.kt:41: Error: Call requires API level 35 (current min is 34): java.util.List#removeFirst [NewApi]
list.removeFirst()
To fix the runtime exception and lint errors, the removeFirst()
and removeLast()
function calls can be replaced with removeAt(0)
and removeAt(list.lastIndex)
respectively in Kotlin. The Android Studio Ladybird also provides a quick fix option for these errors.
Consider removing @SuppressLint("NewApi")
and lintOptions { disable 'NewApi' }
if the lint option has been disabled.
We will update
lb...@gmail.com <lb...@gmail.com> #13
It's just removing the first item of a list...
Are there other weird changes that break stuff?
lb...@gmail.com <lb...@gmail.com> #14
vi...@google.com <vi...@google.com> #15
For the original issue, the warning and lint error is working as intended, because ignoring the warning could break stuff on Android 14 or lower device. The IDE should provide a quick fix option.
For backward compatibility, please follow
Description
If you try to use it on Android 34 and below, it will work fine:
This was tested on Pixel 6 with Android 14 (API 34).
I'm sure it works fine before too. I used it for a very long time.
If you set compileSdk&targetSdk to 34, the warning also goes away.