Search code examples
androidmvvmobservers

error: cannot find symbol class Observer while implementing observers


Am working with an MVVM design pattern ,implementing Observers and things. but all of the sudden Observer Class not found.

error: cannot find symbol class Observer

I have tried

  • Rebuilding project
  • clean project
  • Invalidate/caches & restart

But still no Improvement

here is my gradle file

apply plugin: 'com.android.application'

android {
  compileSdkVersion 29


dataBinding{
    enabled=true
}



defaultConfig {
    applicationId "com.istrides.petool"
    minSdkVersion 17
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }
 }

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.12'
compile project(':horizontalcalendar')
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.17'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.synnapps:carouselview:0.1.5'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.android.libraries.places:places:2.0.0'
implementation 'com.facebook.shimmer:shimmer:0.1.0@aar'

//mvvm
def lifecycle_version = "2.1.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"

//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'

}

Solution

  • Please try adding these libraries in build.gradle

    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.1.0'