Unresolved reference viewModels

Code with problem:

package com.example.android.unscramble.ui.game

import androidx.lifecycle.ViewModel
import androidx.fragment.app.viewModels

class GameViewModel : ViewModel() {
private val viewModel: GameViewModel by viewModels() //-> unresolved
}

I already have the dependencies:

dependencies {
implementation ‘androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1’
implementation ‘androidx.activity:activity-ktx:1.2.3’
implementation ‘androidx.fragment:fragment-ktx:1.3.3’
}

1 Like

it works, try checking the solution code

This worked perfectly for me

If you’re still having the problem invalidating cache worked for me