In Android documentation it's written that we might add dependencies for ViewModel into Gradle like this:
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version" // use -ktx for Kotlin
However, I really cannot find the way to specify the lifecycle_version. I've already tried with File -> Project Structure -> app -> Dependencies -> Add button doesn't work.
It may be too straightforward, but I really can't find a way.
You specify a variable directly into your app level build.gradle file:
def lifecycle_version = "1.1.1"
Some projects configure this in the project level build.gradle file like so:
ext {
dagger = '2.16'
}
And use it like this:
implementation "com.google.dagger:dagger:${dagger}"
implementation "com.google.dagger:dagger-android-support:${dagger}"
Finally, if you don't want to use variables you can simply use the version name instead:
implementation "android.arch.lifecycle:viewmodel:1.1.1"
You can check what is the current version in the Arch Components docs and notes.
For lifecycle the current version is 1.1.1 if you're not using AndroidX