Android Studio cannot find anything under kotlinx
Unresolved reference: kotlinxShort 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.
Fix it fast
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/kotlin2Match what you see, then jump to its fix
- 1
import kotlinx.android.synthetic.main.<layout>.*The import is kotlinx.android.synthetic (Kotlin Android Extensions)Fix - 2
import kotlinx.coroutines.* is redkotlinx-coroutines is not a dependency of the moduleFix - 3
import kotlinx.serialization.* is red, or @Serializable is unresolvedkotlinx-serialization plugin or library is missingFix
- 1
What does the error look like?
Unresolved reference: kotlinximport 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 assembleDebugConfirmed by developer.android.com
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 assembleDebugConfirmed by github.com
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 assembleDebugConfirmed by kotlinlang.org
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:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Android build fails because a product flavor has no flavor dimension
The flavor 'flavor_name' is not assigned to a flavor dimension.
Android Gradle plugin refuses to build when a product flavor is not assigned to a flavor dimension.
2 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
Android build fails because two libraries ship the same META-INF file
More than one file was found with OS independent path
Two dependencies put a file at the same path inside the APK and the plugin will not guess which one wins.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix