ViewModel in Kotlin: Unresolved Reference

Include the following as a dependency:

implementation "android.arch.lifecycle:extensions:1.1.1"

The equivalent AndroidX dependency is:

"androidx.lifecycle:lifecycle-extensions:VERSION"

in where VERSION can be replaced for Current Stable, Beta or Alpha values given in this official link

This dependency is for both ViewModel and LiveData and thus would not require you to give separate dependencies for the same either; i.e. the first two dependencies indicated by you can be replaced by the aforementioned lifecycle extensions dependency.


In my case I was missing :

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