/errors/kotlin/unresolved-reference
Kotlin: error: unresolved reference 'x' (Unresolved reference: x)
- tool
- Kotlin
- exit code
- 1
- versions
- Kotlin 1.x (Unresolved reference: x), Kotlin 2.x K2 compiler (unresolved reference 'x')
- os
- any
unresolved reference 'x' means the Kotlin compiler found no declaration named x that is visible from that line: no local variable, member, import or dependency provides it. The usual causes are a typo, a missing import, or a library that is not on the module's classpath (a dependency missing from build.gradle.kts, or a Gradle sync that has not run). Fix the name, add the import, or add the dependency and rebuild.
What it looks like
Output of the Kotlin 2.3 command-line compiler (K2) for a file with a typo and an import from a library that is not a dependency:
import kotlinx.coroutines.launch
fun main() {
val name = "Ada"
println(nmae)
}Main.kt:1:8: error: unresolved reference 'kotlinx'.
import kotlinx.coroutines.launch
^^^^^^^
Main.kt:5:13: error: unresolved reference 'nmae'.
println(nmae)
^^^^The K1 front end (Kotlin 1.x, or Kotlin 2.x with -language-version 1.9) prints the older wording: error: unresolved reference: kotlinx and error: unresolved reference: nmae. IntelliJ IDEA and Android Studio report the same diagnostic in the editor.
Fixes
| Unresolved name | Fix |
|---|---|
| A typo in your own code | Correct the name; the IDE quick fix lists similar names |
| A class or function from another package | import com.example.util.formatDate |
| kotlinx.coroutines, kotlinx.serialization | add the library to dependencies in build.gradle.kts and sync |
| An extension function (for example a Ktor or Compose extension) | import the extension itself, not only its receiver type |
| Generated code (ViewBinding, BuildConfig, Room, KSP) | enable the feature in Gradle and build the project once |
| A private declaration in another file | change the visibility to internal or public |
A dependency for a JVM or Android module:
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
}In a multiplatform project, add it to the source set that uses it (commonMain.dependencies { ... }); code in commonMain cannot see a dependency declared only for jvmMain.