koin icon indicating copy to clipboard operation
koin copied to clipboard

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/koin/androidx/viewmodel/GetViewModelKt

Open shamshadpattani opened this issue 1 year ago • 3 comments

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

shamshadpattani avatar Dec 27 '24 17:12 shamshadpattani

Seems a linking/classpath problem - NoClassDefFoundError

arnaudgiuliani avatar Jan 16 '25 17:01 arnaudgiuliani

In my case it was koin version above 4 and koin-androidx-compose in version 3.5.5

senpl avatar Apr 15 '25 08:04 senpl

I patched on 4.0.4 to help on that. Did you tried?

arnaudgiuliani avatar Apr 15 '25 08:04 arnaudgiuliani

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.

stale[bot] avatar Sep 12 '25 11:09 stale[bot]