Search code examples
androidkotlindata-bindingandroid-databindingandroid-jetpack

Android databinding: cannot find ...BindingImpl in generated databinding file


I am trying to databind a viewmodel using the example project android-sunflower. The current issue is that when I am trying to build the project I get the error error: cannot find symbol symbol: class FragmentShopBindingImpl location: package {{packageName}}.databinding in the class DataBindinMapperImpl I'm not really sure what I am missing here, since I added everything from the example project. The class FragmentShopBindingImpl does not get generated, or shouldn't it? Since I cannot see any occurence of a class ending with 'Impl' in the android sunflower example
My code:

override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val factory = InjectorUtils.provideShopViewModelFactory(context!!)
        val shopViewModel = ViewModelProviders.of(this, factory)
            .get(ShopViewModel::class.java)

        val binding = DataBindingUtil.inflate<FragmentShopBinding>(
            inflater, R.layout.fragment_shop, container, false).apply {
            viewModel = shopViewModel
            lifecycleOwner = this@ShopFragment
        }

        return binding.root
    }

Layout:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <data>
        <variable
            name="viewModel"
            type="{{packageName}}.viewmodel.ShopViewModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".fragments.ShopFragment">

        <TextView
            android:text="@{viewModel}"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>
</layout>

Image of generated file (ignore the {{packageName}}:

enter image description here


Solution

  • It seems the only thing I had to add was <import type="android.view.View" /> in the data tags...