ViewBinding - Different Flavor Layout Resource

白昼怎懂夜的黑 提交于 2020-03-23 08:00:10

问题


I have a flavor which contains the same layout resource that is in my main source set. This is so it overrides the main one with the flavor specific one. I have done this in many places and it works fine until I introduced ViewBinding. For accuracy, the layout is a nested layout that is "included" in a fragment.

Here is the structure:

main
 - res 
 - - layout 
 - - - layout_sign_up_details_fields.xml
flavor 
 - res 
 - - layout 
 - - - layout_sign_up_details_fields.xml

I have a view, whose ID is til_sudf_first_name, in my flavor specific layout resource that I do not have in my main resource. This is intended. I can see this View is "bound" in my binding class by looking in the generated sources when running this build variant.

@NonNull
public final TextInputLayout tilSudfFirstName;

Now the actual binding happens in a "base" class and is shared with child classes using the protected visibility modifier like so:

private var _binding : FragmentSignUpDetailsBinding? = null
protected val binding get() = _binding!!
protected val detailsBinding get() = binding.lSudfDetails

The problem is detailsBinding does not contain the view I require even though it's present in the generated class.

In addition, the other strange thing is even though there are views in the main layout file that are not in the flavor specific layout file, they are still included in the generated layout file.

Is what I am trying to do even possible? The workaround available to me is to use kotlin's synthetic view handling for this instance like I have been but I was trying to use the recommended approach

来源:https://stackoverflow.com/questions/60549985/viewbinding-different-flavor-layout-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!