简体   繁体   中英

Android Studio data binding error, cannot resolve symbol

I have a perfectly working project. It didn't give any error or anything. But today I upgraded my Android Studio to 4.0 version and Gradle plugin version to 4.0.0. Then I changed my gradle file.

So I change it from this

viewBinding {
        enabled = true
    }

to this

buildFeatures{
        dataBinding = true
    }

I sync my project. But it gives "cannot resolve symbol" error with my databindings.

I have a xml named "activity_admin_screen.xml" so I have variable like this

private  ActivityAdminScreenBinding binding;

This was working perfectly but now it gives cannot resolve symbol error. I tried invalidate and restart a few times. I deleted project from my computer and clone it from my github again as a new project. I tried to write another xml files. But none of them recognized. I tried to write a new xml named activity_admin_screen2.xml. When I tried to write is as ActivityAdminScreen2Binding Android Studio doesn't recognize it.

I tried to Rebuild my entire project this doesn't help either. Can anyone help me with it I can't run my project.

I didn't post any code because this code works with previous Android Studio version perfectly. After the update no code changed but it doesn't work. I made a research but everyone says there is no need to change bindings. They say Android studio should take care of it. Thanks in advance I am open for any possible solution.

Solution:

I changed this

buildFeatures{
        dataBinding = true
    }

to this

buildFeatures{
        viewBinding = true
    }

Now it is working perfectly.

For android studio 4.0, You should try with viewBinding = true

android {
    buildFeatures {
        viewBinding = true
    }
}

Then Clean-Rebuild .

You might want to add both:

android {
    buildFeatures {
        viewBinding = true
    }

    buildFeatures {
        dataBinding = true
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM