Malorimorow
Malorimorow

Reputation: 33

unresolved reference :viewModels

I am new to android kotlin and I am using viewModel in my OCR App."import androidx.fragment.app.viewModels" is not showing.I have added all the neccessary dependencies.What am doing wrong ?

Here are the dependencies.

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'



    implementation 'com.google.android.material:material:1.2.1'

    //lottie animation
    implementation 'com.airbnb.android:lottie:3.4.1'

    // Add CameraX dependencies
    def camerax_version = "1.0.0-beta05"
    implementation "androidx.camera:camera-core:${camerax_version}"
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    implementation "androidx.camera:camera-lifecycle:${camerax_version}"
    implementation "androidx.camera:camera-view:1.0.0-alpha12"

    // Add ML Kit dependencies
    implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.0.0'
    implementation 'com.google.mlkit:language-id:16.0.0'
    implementation 'com.google.mlkit:translate:16.0.0'



}

And these is the import error.

enter image description here

Upvotes: 1

Views: 2452

Answers (1)

Saurabh Thorat
Saurabh Thorat

Reputation: 20664

Add this dependency to use by viewModels() in a Fragment:

implementation 'androidx.fragment:fragment-ktx:1.2.5'

Upvotes: 3

Related Questions