ViewBinding of included library will not generated

Viewed 431

Im kinda stuck here:

We have a UI Component library we're using all over the place in the project. Also the viewbinding get generated for those layouts which works fine.

I stuck when i try to include those layouts in the main project in another layout like this:

<FrameLayout ...>
   <include id="@+id/includedLayoutFromLib" layout="@layout/someLibraryLayout"/>
</FrameLayout>

I've read about how to include a layout (I do not make use of merge here).

I cannot access the included views:

 binding.includedLayoutFromLib.title 

I would expect "title" to be accessible from the included binding when an ID for the include is set. All views have IDs also in the included one

Is this a bug or what i miss here ?

thx

3 Answers

I also face the same problem,it`s very very ...,for change bing.view.findViewById(R.id.test) maybe work.

I did quick check and had similar case I think, separate module with layouts, included those in other module's layout and it all worked nice. Perhaps you could check gradle configuration if you have

android {
   buildFeatures { viewBinding = true } 
}

set in both modules. Also I would start wirh clean build, gradle sync or even android studio invalidate cache / restart just to rule out some junk build files as source of problem.

Also other question: is this UI Component lib precompiled or is it a module in your project. From what I see it also should work but perhaps it would require some extra configuration in such case?

Since viewing binding works for me like the way you have mentioned, I would recommend Clean Project then invalidate caches/restart, and then Rebuild Project. What version of the android studio are you using?

Related