google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.41k stars 2.01k forks source link

force close app after upgrade to 2.43 [Jetapack Compose] #3484

Closed Daeng96 closed 2 years ago

Daeng96 commented 2 years ago
java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`
        at androidx.lifecycle.SavedStateHandleSupport.createSavedStateHandle(SavedStateHandleSupport.kt:91)
        at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:89)
        at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:111)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:187)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:153)
        at androidx.lifecycle.viewmodel.compose.ViewModelKt.get(ViewModel.kt:215)
        at androidx.lifecycle.viewmodel.compose.ViewModelKt.get$default(ViewModel.kt:195)
        at androidx.lifecycle.viewmodel.compose.ViewModelKt.viewModel(ViewModel.kt:120)
.....

dependencies:

implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0'
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
implementation 'androidx.activity:activity-compose:1.5.0'
danysantiago commented 2 years ago

Are you using Jetpack Navigation too (androidx.navigation:navigation-compose)? Can you verify the version being used is 2.5.0 ?

nuhkoca commented 2 years ago

Was having the same problem but after adding androidx.navigation:navigation-compose:2.5.0, the crash is gone but do we really need compose-navigation explicitly if we use hilt-navigation-compose?

Daeng96 commented 2 years ago

Was having the same problem but after adding androidx.navigation:navigation-compose:2.5.0, the crash is gone but do we really need compose-navigation explicitly if we use hilt-navigation-compose?

Ok, thanks. Work

dshokouhi commented 2 years ago

We had also experienced this error in the Home Assistant app. We already had the navigation-compose dependency mentioned. We needed to add androidx.fragment dependency and the crash went away. Just commenting here for the next person who may get stuck :)

iwo commented 2 years ago

I had the same issue and resolved it by adding implementation("androidx.fragment:fragment-ktx:1.5.1") dependency. Fragment.viewModels() is defined in this library and previously it was only transitive dependency resolved to the older version.

voghDev commented 1 year ago

In my case, I was having this issue and I solved it by upgrading navigation to 2.5.1. I'm not using navigation-compose as previous answers say, so I'll include the list of my dependencies related to navigation in case it is helpful somebody else:

    navigation_version = "2.5.1"
    compose_version = "1.2.0"
    kotlin_version = "1.7.0"
    dagger_hilt_version = "2.43.2"

    implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
    implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
    implementation "androidx.navigation:navigation-dynamic-features-fragment:$navigation_version"

// Unit tests
    testImplementation "androidx.navigation:navigation-testing:$navigation_version"
// UI tests
    androidTestImplementation "androidx.navigation:navigation-testing:$navigation_version"
gerardoepitacio commented 1 year ago

We had also experienced this error in the Home Assistant app. We already had the navigation-compose dependency mentioned. We needed to add androidx.fragment dependency and the crash went away. Just commenting here for the next person who may get stuck :)

Yes totally required to add "androidx.fragment:fragment-ktx", even if you are not using any Fragment in your module, working in Hilt v2.44.

hagau-ioan commented 1 year ago

Indeed as @gerardoepitacio mentioned "androidx.fragment:fragment-ktx" was the fix. Thx.

ZyBrew07 commented 1 year ago

latest androidx.navigation:navigation-fragment-ktx version supplied to my modules fixed the error

shalva97 commented 1 year ago

Added implementation("androidx.fragment:fragment-ktx:1.5.1") but it did not solve the crash. Am I the only one?

I do not use Fragment.viewModels() instead I call hiltViewModel() extension

shinewanna commented 8 months ago

Are you using Jetpack Navigation too (androidx.navigation:navigation-compose)? Can you verify the version being used is 2.5.0 ?

This saved my life!!! Thanks