Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

by viewModels() Unresolved reference

I have a problem, Android Studio highlights by viewModels() as an error, but the code is successfully compiled and works. This problem occurs only in Activity, in Fragment there is no such error. The same will happen if I use by viewModel() (Koin) instead of by viewModels(). I’ve looked at a lot of decisions, but none of them helped me.

I tried:

  • Invalidate Caches
  • Restart IDE, PC...
  • Open a project on another PC
  • Tried this answer and this

Error

My dependencies (app):

implementation(project(":domain"))
implementation(project(":data"))

implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

def koin_version= "3.2.1"
implementation "io.insert-koin:koin-android:$koin_version"

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.8.0-alpha01'
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'
implementation "androidx.fragment:fragment-ktx:1.5.3"
implementation 'com.my.target:mytarget-sdk:5.15.4'

def lottieVersion = "5.2.0"
implementation "com.airbnb.android:lottie:$lottieVersion"

implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.13'
implementation 'com.google.firebase:firebase-config-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.android.gms:play-services-auth:20.3.0'
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'com.google.android.gms:play-services-location:20.0.0'

implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'

Build gradle (project):

buildscript {
    repositories {
        google()
    }
    dependencies {
        classpath 'com.google.android.gms:oss-licenses-plugin:0.10.5'
        classpath 'com.google.gms:google-services:4.3.14'
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
    }
}
plugins {
    id 'com.android.application' version '7.3.0' apply false
    id 'com.android.library' version '7.3.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.7.10' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 409
Murzify Avatar asked Mar 23 '26 06:03

Murzify


1 Answers

I have this issue also. AppCompatActivity is deriving from ComposeActivity but somehow Android Studio isn't getting this and showing it as an error.

like image 165
Johan C Avatar answered Mar 24 '26 21:03

Johan C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!