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
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'
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, eg 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?
You have made some typo error: use =
and not :
:
val myBuffer = mutableListOf<Byte>()
or specify type explicitly:
val myBuffer: MutableList<Byte> = mutableListOf<>()
未解决的mutableListOf
或MutableList
引用请尝试实现此依赖项:
implementation 'androidx.core:core-ktx:$kotlin_version'
lates version:
val myBuffer: MutableList<Byte> = mutableListOf()
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.