Android Data Binding: missing DataBinderMapper class

后端 未结 5 1049
忘掉有多难
忘掉有多难 2020-12-11 07:49
java.lang.NoClassDefFoundError: android.databinding.DataBinderMapper
        at android.databinding.DataBindingUtil.(DataBindingUtil.java:31)
        a         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 08:02

    I was having this issue this last week, and was having a hard time figuring it out, but finally I discovered that I had two layouts with the same name in different libraries that each use databinding. I'm guessing this was causing the generated binding classes to end up in some kind of bad state at runtime.

    I was able to troubleshoot it into a situation where, instead of getting this error on one Fragment, I got a ClassCastException to happen on the Fragment that had a layout with the same name. The generated Binding class was trying to cast a LinearLayout into a RelativeLayout. The only way it could be doing this is if it were trying to use a layout file from a completely different module that had the same name.

    After making sure there were no layouts that share the same name -- even across different library modules -- it cleared up.

提交回复
热议问题