scorpiodawg
12/05/2019, 4:55 PMclass DetailActivity : AppCompatActivity() {
// Lazy inject ViewModel
val detailViewModel: DetailViewModel by viewModel()
}
But the usage of viewModel()
fails in Android Studio with the following error: Expression 'viewModel' of type 'DetailViewModel' cannot be invoked as a function. The function 'invoke()' is not found
. However, using the by sharedViewModel()
in a Fragment to inject it works correctly. My Gradle file includes:
// Koin for Android
implementation "org.koin:koin-android-viewmodel:$koin_version"
// or Koin for AndroidX scoping
implementation "org.koin:koin-androidx-scope:$koin_version"
// or Koin for Android Architecture ViewModel (AndroidX)
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
and koin_version is 2.0.1. Any help is appreciated!