sunflower20
sunflower20

Reputation: 499

How to get the version for lifecycle libraries in Gradle?

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.

Upvotes: 2

Views: 2711

Answers (2)

Levi Moreira
Levi Moreira

Reputation: 12005

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

Upvotes: 3

SpiritCrusher
SpiritCrusher

Reputation: 21043

You need to define version.

android {
    ....
    ext {
        lifecycle_version = "1.1.1"
    }
}



dependencies {
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
  }

Or just use

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

Check Architecture Components Release Notes for latest version and new features.

Upvotes: 1

Related Questions