I want to create a ViewModel for my project,I also added the dependencies but it shows this error, how can I fix it?Also I am using the latest version of Android Studio and Java
Could not get unknown property 'lifecycle_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
dependencies {
//ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}```
CodePudding user response:
You have to define your lifecycle_version.
dependencies {
//Define your version here
def lifecycle_version = "2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
//Other Dependencies
}
Check here: https://developer.android.com/jetpack/androidx/releases/lifecycle#groovy