After removing the existing DataBinding
from the project, I also wanted to get rid of the kotlinx.android.synthetic
and replace it with ViewBinding
.
However, after enabling ViewBinding
in my project, I'm still not able to do a proper setup.
Trying to invoke the ViewBinding
into my MainActivity
or in one of my fragments I get the following error in the inflate
method:
Cannot access 'no_name_in_PSI_...' which is a supertype of 'com.example.projectname.databinding.ActivityMainBinding'. Check your module classpath for missing or conflicting dependencies
For example:
MainActivity.kt
class MainActivity : BaseActivity<SharedViewModel>() {
private lateinit var binding: ActivityMainBinding
...
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
}
}
My build.gradle (:app)
is properly set up:
build.gradle (:app)
android {
...
buildFeatures {
viewBinding true
}
}
I've used ViewBinding
in another project of mine and it worked out of the box. Please help. Thank you so much.
I had the same error. I added the layout tag in my xml files and that's not correct. Layout tag is for data binding but here we are only enabling view binding feature. That's why you are getting that error. Just remove the layout tag. Edit- I am elaborating this answer since it is not clear. Remove the tag from your XML file. Reason- As stated in android data binding documentation, is used when "dataBinding" is enabled. But here you have enabled "viewBinding" for which should not be used in XML file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With