I'm currently building an app that uses compose TextFieldState
and now I'm facing this error whenever im running the app:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/foundation/text2/input/TextFieldState;
at com.example.auth.presentation.login.phoneNumber.LoginState.<init>(LoginState.kt:9)
at com.example.auth.presentation.login.phoneNumber.LoginViewModel.<init>(LoginViewModel.kt:27)
at com.example.auth.presentation.di.AuthViewModelModuleKt$authViewModelModule$1$invoke$$inlined$viewModelOf$default$1.invoke(ViewModelOf.kt:231)
at com.example.auth.presentation.di.AuthViewModelModuleKt$authViewModelModule$1$invoke$$inlined$viewModelOf$default$1.invoke(ViewModelOf.kt:63)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:50)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:109)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:247)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:233)
at org.koin.core.scope.Scope.get(Scope.kt:212)
at org.koin.androidx.viewmodel.factory.KoinViewModelFactory.create(KoinViewModelFactory.kt:25)
at androidx.lifecycle.ViewModelProvider$Factory.create(ViewModelProvider.android.kt:158)
at androidx.lifecycle.viewmodel.ViewModelProviderImpl_androidKt.createViewModel(ViewModelProviderImpl.android.kt:34)
at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release(ViewModelProviderImpl.kt:65)
at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release$default(ViewModelProviderImpl.kt:47)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:91)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:109)
at org.koin.androidx.viewmodel.GetViewModelKt.resolveViewModel(GetViewModel.kt:43)
at com.example.auth.presentation.login.phoneNumber.LoginScreenKt.LoginScreenRoot(LoginScreen.kt:162)
at com.example.samanins.NavigationRootKt$authGraph$1$1.invoke(NavigationRoot.kt:33)
at com.example.samanins.NavigationRootKt$authGraph$1$1.invoke(NavigationRoot.kt:32)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:139)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.navigation.compose.NavHostKt$NavHost$14$1.invoke(NavHost.kt:308)
at androidx.navigation.compose.NavHostKt$NavHost$14$1.invoke(NavHost.kt:306)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:401)
at androidx.compose.runtime.saveable.SaveableStateHolderImpl.SaveableStateProvider(SaveableStateHolder.kt:85)
at androidx.navigation.compose.NavBackStackEntryProviderKt.SaveableStateProvider(NavBackStackEntryProvider.kt:65)
at androidx.navigation.compose.NavBackStackEntryProviderKt.access$SaveableStateProvider(NavBackStackEntryProvider.kt:1)
at androidx.navigation.compose.NavBackStackEntryProviderKt$LocalOwnersProvider$1.invoke(NavBackStackEntryProvider.kt:52)
at androidx.navigation.compose.NavBackStackEntryProviderKt$LocalOwnersProvider$1.invoke(NavBackStackEntryProvider.kt:51)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
at androidx.navigation.compose.NavBackStackEntryProviderKt.LocalOwnersProvider(NavBackStackEntryProvider.kt:47)
at androidx.navigation.compose.NavHostKt$NavHost$14.invoke(NavHost.kt:306)
at androidx.navigation.compose.NavHostKt$NavHost$14.invoke(NavHost.kt:295)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:139)
And I've heard that it maybe a version mismatch so this is my version catalog:
[versions]
agp = "8.5.2"
androidTools = "31.2.2"
core = "1.10.3"
#noinspection RiskyLibrary
playCore = "1.10.3"
coreSplashscreen = "1.0.1"
coilCompose = "2.6.0"
composeCompiler = "1.5.9"
desugar_jdk_libs = "2.0.4"
kotlin = "1.9.22"
coreKtx = "1.12.0"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
activityCompose = "1.8.2"
ktor = "2.3.8"
ktorClientLogging = "2.3.8"
ktorServerCallLogging = "2.3.7"
koin = "3.5.3"
lifecycleRuntimeKtx = "2.7.0"
composeBom = "2024.05.00" #"2024.02.02"
materialIconsExtended = "1.6.3"
navigationCompose = "2.7.7"
securityCryptoKtx = "1.1.0-alpha06"
timber = "5.0.1"
ksp = "1.9.22-1.0.17"
room = "2.6.1"
appcompat = "1.6.1"
material = "1.11.0"
org-jetbrains-kotlin-jvm = "1.9.22"
maps = "4.3.3"
coroutines = "1.8.0"
gmsLocation = "21.2.0"
mapsUtils = "5.0.0"
bson = "4.11.1"
work = "2.9.0"
kotlinx-serialization = "1.6.3"
secretsPlugin = "2.0.1"
playServicesMaps = "18.2.0"
annotation = "1.7.1"
material3Android = "1.3.0"
# Project versions
projectApplicationId = "com.plcoding.samanins"
projectVersionName = "1.0"
projectMinSdkVersion = "26"
projectTargetSdkVersion = "34"
projectCompileSdkVersion = "34"
projectVersionCode = "1"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "coreSplashscreen" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycleRuntimeKtx" }
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleRuntimeKtx" }
androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "materialIconsExtended" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
androidx-security-crypto-ktx = { module = "androidx.security:security-crypto-ktx", version.ref = "securityCryptoKtx" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" }
core = { module = "com.google.android.play:core", version.ref = "playCore" }
core-testing = { module = "com.google.android.play:core-testing", version.ref = "playCore" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization"}
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines"}
kotlinx-coroutines-play-services = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-play-services", version.ref = "coroutines"}
desugar-jdk-libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar_jdk_libs" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-work = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "work" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
koin-android-workmanager = { group = "io.insert-koin", name = "koin-androidx-workmanager", version.ref = "koin" }
koin-android = { group = "io.insert-koin", name = "koin-android", version.ref = "koin" }
koin-core = { group = "io.insert-koin", name = "koin-core", version.ref = "koin" }
koin-androidx-compose = { group = "io.insert-koin", name = "koin-androidx-compose", version.ref = "koin" }
ktor-client-auth = { module = "io.ktor:ktor-client-auth", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktorClientLogging" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-server-call-logging = { module = "io.ktor:ktor-server-call-logging", version.ref = "ktorServerCallLogging" }
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
google-maps-android-compose = { module = "com.google.maps.android:maps-compose", version.ref = "maps" }
google-android-gms-play-services-location = { module = "com.google.android.gms:play-services-location", version.ref = "gmsLocation"}
org-mongodb-bson = { module = "org.mongodb:bson", version.ref = "bson" }
play-services-maps = { group = "com.google.android.gms", name = "play-services-maps", version.ref = "playServicesMaps" }
google-maps-android-utils-ktx = { module = "com.google.maps.android:maps-utils-ktx", version.ref = "mapsUtils"}
annotation = { group = "androidx.annotation", name = "annotation", version.ref = "annotation" }
androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" }
# Gradle
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
android-tools-common = { group = "com.android.tools", name = "common", version.ref = "androidTools" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }
room-gradlePlugin = { group = "androidx.room", name = "room-gradle-plugin", version.ref = "room" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
room = { id = "androidx.room", version.ref = "room" }
jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "org-jetbrains-kotlin-jvm" }
androidDynamicFeature = { id = "com.android.dynamic-feature", version.ref = "agp" }
mapsplatform-secrets-plugin = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secretsPlugin"}
samanins-android-application = { id = "samanins.android.application", version = "unspecified" }
samanins-android-application-compose = { id = "samanins.android.application.compose", version = "unspecified" }
samanins-android-library = { id = "samanins.android.library", version = "unspecified" }
samanins-android-library-compose = { id = "samanins.android.library.compose", version = "unspecified" }
samanins-android-feature-ui = { id = "samanins.android.feature.ui", version = "unspecified" }
samanins-android-room = { id = "samanins.android.room", version = "unspecified" }
samanins-jvm-library = { id = "samanins.jvm.library", version = "unspecified" }
samanins-jvm-ktor = { id = "samanins.jvm.ktor", version = "unspecified" }
The versions that you see have a different version commented infront of them mean that they were tried too.
From the documentation of TextFieldState
:
Added in 1.7.0
You use the Compose BOM 2024.05.00
which uses the Compose foundation library in version 1.6.7.
From the official BOM Mapping, the first BOM using 1.7.0 is 2024.09.00
. Updating the version accordingly should fix that.
Please also note that during development this class changed packages, so make sure you use the correct import statement:
import androidx.compose.foundation.text.input.TextFieldState