Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Android Studio cannot find anything under kotlinx

ErrorUnresolved reference: kotlinx

Short answer

Unresolved reference: kotlinx has three common causes. kotlinx.android.synthetic was removed, so switch to view binding. The kotlinx-coroutines dependency is missing from build.gradle. Or the kotlinx-serialization plugin and library are not added. Check which package the import points to, then apply the matching fix.

  • Applies to Kotlin 2.x, Android Studio Otter, AGP 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the import line that is red. The word after kotlinx tells you which cause below applies.

    grep -rn "import kotlinx" app/src/main/java app/src/main/kotlin
  2. 2Match what you see, then jump to its fix

    1. 1import kotlinx.android.synthetic.main.<layout>.*The import is kotlinx.android.synthetic (Kotlin Android Extensions)Fix
    2. 2import kotlinx.coroutines.* is redkotlinx-coroutines is not a dependency of the moduleFix
    3. 3import kotlinx.serialization.* is red, or @Serializable is unresolvedkotlinx-serialization plugin or library is missingFix

What does the error look like?

  • Unresolved reference: kotlinx
  • import kotlinx.android.synthetic.main.activity_main.*

Cause 1 of 3

The import is kotlinx.android.synthetic (Kotlin Android Extensions)

1Check

Kotlin Android Extensions is deprecated, and using synthetics for view binding is no longer supported. Look for the old plugin in the module build file.

grep -rn "android-extensions\|android.extensions" app/build.gradle*

2Fix

Remove the synthetic imports and the old plugin, turn on view binding and use the generated binding class.

// app/build.gradle.kts
android {
    buildFeatures {
        viewBinding = true
    }
}

// Activity
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)
    binding.name.text = "Hello"
}

3Verify

Sync Gradle and rebuild. The binding class is named after the layout file, so activity_main.xml gives ActivityMainBinding.

./gradlew assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

kotlinx-coroutines is not a dependency of the module

1Check

Coroutines live in a separate library. The core module is needed for the API and the android module gives Dispatchers.Main.

grep -n "coroutines" app/build.gradle*

2Fix

Add both dependencies to the module that uses them, then sync.

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.11.0")
}

3Verify

Sync the project and rebuild; the import resolves.

./gradlew assembleDebug

Confirmed by github.com

Did this fix it?

Cause 3 of 3

kotlinx-serialization plugin or library is missing

1Check

Serialization needs both a compiler plugin and the JSON library.

grep -n "serialization" app/build.gradle*

2Fix

Add the plugin and the library. Use the Kotlin version your project already uses for the plugin.

plugins {
    kotlin("plugin.serialization") version "2.4.21"
}

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.11.0")
}

3Verify

Sync and rebuild; @Serializable and Json resolve.

./gradlew assembleDebug

Confirmed by kotlinlang.org

Did this fix it?

How do I stop it coming back?

  • Add a library to the module that imports it, not only to the root project.
  • Keep the serialization plugin on the same Kotlin version as the Kotlin plugin.
  • Move off deprecated Kotlin plugins as soon as the compiler warns about them.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.