androidkotlinandroid-gradle-pluginkotlin-android-extensionskotlin-coroutines

Unresolved reference: viewModelScope - Kotlin Android


I try to add viewModelScope to a basic viewModel but android studio doesn't recognize it.

I tried to change my gradle build file with some solution I found but nothing works.

Here an extract of my build.gradle app

implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha01"
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01"

When I type viewModelScope in my viewModel it say Unresolved reference: viewModelScope.


Solution

  • for now its in alpha, so please update your gradle to use the following dependencies:

    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"