Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ViewBinding error in the inflate-method - missing or conflicting dependencies

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)
      }
}

enter image description here

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.

like image 356
BWappsAndmore Avatar asked Oct 15 '25 08:10

BWappsAndmore


1 Answers

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.

like image 117
subhra priyadarshinee Avatar answered Oct 17 '25 02:10

subhra priyadarshinee



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!