Describe the bug
Crash when calling getViewModel from Composable.
Crash Log
java.lang.NoSuchFieldError: No field Companion of type Landroidx/compose/runtime/SlotTable$Companion; in class Landroidx/compose/runtime/SlotTable; or its superclasses (declaration of 'androidx.compose.runtime.SlotTable' appears in /data/app/com.troy.tersive-sXbO-PmO4LZyaJ_OdajsiA==/base.apk)
at com.troy.tersive.ui.main.MainActivityKt.MainPage(MainActivity.kt:295)
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The app should work the same and not crash.
Koin project used and used version (please complete the following information):
implementation "org.koin:koin-androidx-viewmodel:2.2.0"
implementation "org.koin:koin-androidx-compose:2.2.0"
implementation "org.koin:koin-androidx-ext:2.2.0"
Meanwhile i am using this workaround:
class MyViewModel : ViewModel() {
// TODO: this is a workaround for koin 2.2.0 not working with compose 1.0.0-alpha07
private val koin = GlobalContext.get()
private val repository = koin.get<MyRepository>()
}
and inject the viewmodel into my composable by using androidx.compose.ui.viewinterop.viewModel (which requires default viewmodel constructor).
@Composable
fun MyView(
myViewModel: MyViewModel = viewModel()
) {
...
}
I have the same crash although I'm not using Koin - only compose alpha07 + compose-navigation alpha01
crash occurs on NavHost initialization:
Scaffold {
NavHost( // <-- right here
navController = navController,
startDestination = "splash",
) {
composable("splash") { SplashScreen() }
}
}
so it might not be caused by or related to Koin
@mykhailo-gaidai I have the same crash with you. I used only compose alpha07 + compose-navigation alpha01. Then I upgraded compose-navigation alpha02. That fix it. But there is a bug on alpha02. Not working backPressed button after rotated screen.
will be updated in 2.2.1 馃憤
Most helpful comment
@mykhailo-gaidai I have the same crash with you. I used only compose alpha07 + compose-navigation alpha01. Then I upgraded compose-navigation alpha02. That fix it. But there is a bug on alpha02. Not working backPressed button after rotated screen.