CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`

Viewed 1112

I'm trying to implement navigation in my app which is built with Jetpack Compose, but when I try to navigate from a screen to another I get:

java.lang.IllegalArgumentException: CreationExtras must have a value by SAVED_STATE_REGISTRY_OWNER_KEY

I'm using:

implementation "androidx.hilt:hilt-navigation-compose:1.0.0"

And here is the code:

if(viewModel.isAuthenticated) {
    navController.navigate(Screen.Profile.route)
}
3 Answers

@Dragan.T 's answer is correct.

Adding

implementation "androidx.navigation:navigation-compose:2.5.1"

Solved my problem. As for why we need to add, I am not so sure but it's Android so anything can happen here.

Insert implementation "androidx.navigation:navigation-compose:2.5.1" into your gradle file. If you already have it, be sure it's updated with the latest (2.5.1) version.

If you use Compose with Fragments, then you may not have the Fragments dependency where viewModels() is defined.

Adding:

implementation "androidx.fragment:fragment-ktx:1.5.2"

to my build.grade script fixed it for me (previously this was a transitive dependency).

Related