Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.4.1, Kotlin "unresolved reference: mutableListOf"

I am building an AAR with Kotlin in Android Studio 3.4.1, and I get the dreaded "unresolved reference" error when I try to use mutableListOf.

 val myBuffer: mutableListOf<Byte>()

I updated Kotlin to the latest version at the time of writing enter image description here

In build.gradle, the Kotlin version is also consistently defined. kotlinversion

In the module build.gradle, the following plugins are used:

apply plugin: 'com.android.library'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

I understood from what I read, that the Kotlin language plugin, including collection classes, should be automatically included in Android Studio. In any case, I'm using other Kotlin classes, e.g. ByteArray, without a problem.

Following advice that I found online, I cleaned and re-built, also selected File | Invalidate Caches/Restart and re-built. It did not work; the reference is still unresolved.

The Kotlin documentation doesn't say that this function is deprecated, which was another possible cause that I found.

What am I missing?

like image 225
user1725145 Avatar asked Jul 04 '19 11:07

user1725145


People also ask

What is unresolved reference error in Kotlin?

To conclude, the unresolved reference error happens when Kotlin has no idea what the keyword you’re typing in the file points to. It may be a function, a variable, or another construct of the language that you’ve yet to declare in the code.

How to remove elements from a mutablelist in Kotlin?

In Kotlin one should use the MutableList.removeAt function instead. Removes a single instance of the specified element from this collection, if it is present. Removes all elements from this MutableList that match the given predicate. Removes all of this collection's elements that are also contained in the specified collection.

Is the Kotlin language plugin automatically included in Android Studio?

I understood from what I read, that the Kotlin language plugin, including collection classes, should be automatically included in Android Studio. In any case, I'm using other Kotlin classes, e.g. ByteArray, without a problem. Following advice that I found online, I cleaned and re-built, also selected File | Invalidate Caches/Restart and re-built.

How to get the version of Kotlin in Gradle?

In build.gradle, the Kotlin version is also consistently defined. In the module build.gradle, the following plugins are used: apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions'


1 Answers

You have made some typo error: use = and not ::

 val myBuffer = mutableListOf<Byte>()

or specify type explicitly:

 val myBuffer: MutableList<Byte> = mutableListOf<>()
like image 109
S-Sh Avatar answered Nov 15 '22 03:11

S-Sh