Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find ViewModelProviders class, only ViewModelProvider

I am trying to create lifecycle-aware view models. But I can't find ViewModelProviders class in my Android project, only ViewModelProvider. There seems to be no android.arch.lifecycle.ViewModelProviders package for me to import as well. What's happening

like image 470
Jack Guo Avatar asked Jun 14 '18 19:06

Jack Guo


1 Answers

You probably have this dependency included in your project:

implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"

That contains ViewModelProvider (and just 4 other classes), but ViewModelProviders is in a different package:

implementation "android.arch.lifecycle:extensions:$lifecycle_version"

Here are the contents of these packages for reference (as of version 1.1.1):

The contents of the extensions and viewmodel packages


For the record, you can find this out yourself by looking up the docs for the ViewModelProviders class, where it says up top:

added in version 1.1.0

belongs to Maven artifact android.arch.lifecycle:extensions:1.1.1

like image 130
zsmb13 Avatar answered Nov 16 '22 03:11

zsmb13