java.lang.NoClassDefFoundError: Failed resolution of: Lorg/koin/androidx/viewmodel/GetViewModelKt
BUG The bug is if i use navigation or anywhere in my *ViewModel" show this error
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/koin/androidx/viewmodel/GetViewModelKt
`import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
class AuthViewmodel(private val authUseCase: AuthUseCase) : ViewModel() {.............}`
actual fun platformModule(): Module = module {
single {
dataStore(get())
}
viewModelOf(::AuthViewmodel)
}
private fun initKoin() {
val modules = sharedKoinModules + platformModule()
startKoin {
androidContext(this@AuditApplication)
modules(modules)
}
}
version: koinCore = "4.0.0"
Error in the page of LoginActivity
class LoginActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
AuditTheme {
AuditLogin()
}
}
}
}
sealed class Screen(val title: String) {
data object LoginScreen : Screen("Login")
data object ClientCodeScreen : Screen("ClientCode")
data object ForgotPasswordScreen : Screen("Forgot")
data object ResetPasswordScreen : Screen("Reset")
data object LoginSuccessScreen : Screen("Success")
}
@Composable
fun AuditLogin() {
val navController = rememberNavController()
Scaffold(
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onBackground,
contentWindowInsets = WindowInsets(0, 0, 0, 0)
) { padding ->
Row(
Modifier
.fillMaxSize()
.padding(padding)
.windowInsetsPadding(
WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal
)
)
) {
val authViewmodel = koinViewModel<AuthViewmodel>()
NavHost(navController, startDestination = Screen.ClientCodeScreen.title) {
// ClientCodeScreen Composable
composable(Screen.ClientCodeScreen.title) {
ClientCodeScreen(navigateToLogin = { navController.navigate(Screen.LoginScreen.title) },authViewmodel)
}
composable(route = Screen.LoginScreen.title,
) { backStackEntry ->
LoginScreen(navigateToForgotPasword = {
navController.navigate(Screen.ForgotPasswordScreen.title)
})
}
val authViewmodel = koinViewModel<AuthViewmodel>()
it show the error
Seems a linking/classpath problem - NoClassDefFoundError
In my case it was koin version above 4 and koin-androidx-compose in version 3.5.5
I patched on 4.0.4 to help on that. Did you tried?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.