androidandroid-studiokotlinandroid-viewbinding

cannot access viewBinding


I'm now using viewBinding with Kotlin.

here is my build.gradle build.gradle

enable ViewBinding and has auto import ViewBinding dependency.

but Android Studio still shows error like this Android Studio Error

but I can build and run with no problem.

and if I add viewBinding in dependencies, then the error is gone.

Does anyone know why?


Solution

  • Facing same issue exact error yesterday. Solution work for me is

    and Error is gone

    Making sure

    1. android.useAndroidX=true. inside gradle.properties file
    2. inside app build.gradle
     buildFeatures {
           viewBinding true
     }
    
    1. Always Use folder structure with samll case latter only class name is allowed to be Uppercase
    2. If you are using any Copyright-Comment at top of xml or Layout tag without variable tag or we can say without any data then remove that and try to clean/rebuild project