欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

AbstractMethodError: abstract method "androidx.databinding.ViewDataBinding androidx.databinding.DataBinderMapper.getDataBinder(androidx.databindi

程序员文章站 2022-08-08 16:41:31
混淆导致的数据绑定库错误 问题摘要 AbstractMethodError: abstract method "androidx.databinding.ViewDataBinding androidx.databinding.DataBinderMapper.getDataBinder(andro ......

混淆导致的数据绑定库错误

问题摘要

abstractmethoderror: abstract method "androidx.databinding.viewdatabinding androidx.databinding.databindermapper.getdatabinder(androidx.databinding.databindingcomponent, android.view.view, int)"

堆栈如下:

java.lang.abstractmethoderror: abstract method "androidx.databinding.viewdatabinding androidx.databinding.databindermapper.getdatabinder(androidx.databinding.databindingcomponent, android.view.view, int)"
        at androidx.databinding.mergeddatabindermapper.getdatabinder(mergeddatabindermapper.java:74)
        at androidx.databinding.databindingutil.bind(databindingutil.java:199)
        at androidx.databinding.databindingutil.inflate(databindingutil.java:130)
        at androidx.databinding.databindingutil.inflate(databindingutil.java:95)
        at cn.sintoon.common.adapter.sinrecyclerviewbaseadapter.oncreateviewholder(unknown source:11)
        at cn.sintoon.common.adapter.sinrecyclerviewbaseadapter.oncreateviewholder(unknown source:0)
        at androidx.recyclerview.widget.recyclerview$adapter.createviewholder(recyclerview.java:6794)
        at androidx.recyclerview.widget.recyclerview$recycler.trygetviewholderforpositionbydeadline(recyclerview.java:5975)
        at androidx.recyclerview.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5858)
        at androidx.recyclerview.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5854)
        at androidx.recyclerview.widget.linearlayoutmanager$layoutstate.next(linearlayoutmanager.java:2230)
        at androidx.recyclerview.widget.linearlayoutmanager.layoutchunk(linearlayoutmanager.java:1557)
        at androidx.recyclerview.widget.linearlayoutmanager.fill(linearlayoutmanager.java:1517)
        at androidx.recyclerview.widget.linearlayoutmanager.onlayoutchildren(linearlayoutmanager.java:612)
        at androidx.recyclerview.widget.recyclerview.dispatchlayoutstep2(recyclerview.java:3924)
        at androidx.recyclerview.widget.recyclerview.onmeasure(recyclerview.java:3336)
        at android.view.view.measure(view.java:23454)
        at androidx.constraintlayout.widget.constraintlayout.internalmeasurechildren(constraintlayout.java:1227)
        at androidx.constraintlayout.widget.constraintlayout.onmeasure(constraintlayout.java:1572)
        at android.view.view.measure(view.java:23454)
        at android.view.viewgroup.measurechildwithmargins(viewgroup.java:6834)
        at android.widget.framelayout.onmeasure(framelayout.java:185)
        at androidx.appcompat.widget.contentframelayout.onmeasure(contentframelayout.java:143)
        at android.view.view.measure(view.java:23454)
        at android.view.viewgroup.measurechildwithmargins(viewgroup.java:6834)
        at androidx.appcompat.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:403)
        at android.view.view.measure(view.java:23454)
        at android.view.viewgroup.measurechildwithmargins(viewgroup.java:6834)
        at android.widget.framelayout.onmeasure(framelayout.java:185)
        at android.view.view.measure(view.java:23454)
        at android.view.viewgroup.measurechildwithmargins(viewgroup.java:6834)
        at android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1565)
        at android.widget.linearlayout.measurevertical(linearlayout.java:847)
        at android.widget.linearlayout.onmeasure(linearlayout.java:726)
        at android.view.view.measure(view.java:23454)
        at android.view.viewgroup.measurechildwithmargins(viewgroup.java:6834)
        at android.widget.framelayout.onmeasure(framelayout.java:185)
        at com.android.internal.policy.decorview.onmeasure(decorview.java:847)
        at android.view.view.measure(view.java:23454)
        at android.view.viewrootimpl.performmeasure(viewrootimpl.java:2954)
        at android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1753)
        at android.view.viewrootimpl.performtraversals(viewrootimpl.java:2041)
        at android.view.viewrootimpl.dotraversal(viewrootimpl.java:1636)
        at android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:7946)
        at android.view.choreographer$callbackrecord.run(choreographer.java:1092)
        at android.view.choreographer.docallbacks(choreographer.java:893)
        at android.view.choreographer.doframe(choreographer.java:812)
        at android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:1078)
        at android.os.handler.handlecallback(handler.java:907)

出现场景

封装了一个类库,向外提供一个封装好的 recycleradapter,使用 databinding 。生成类库时开启了混淆,在使用时,抛出异常。

问题原因

androidx.databinding.databindingcomponent 混淆掉了。

如何修复

修改混淆规则。不混淆这个类。

-keep class androidx.databinding.databindingcomponent {*;}

排查过程

根据错误堆栈看,是找不到这个方法,初步怀疑就是被混淆掉了方法,然后直接使用不混淆的测试,的确没有异常了。确认是混淆的问题。

然后在 /build/outputs/mapping/ 目录下查看 mapping.txt 文件,发现果然是将这类混淆掉了。

# compiler: r8
# compiler_version: 1.4.77
# min_api: 1
androidx.databinding.databindingcomponent -> a.a.a:

mapping.txt 这个文件提供混淆前后类、方法、类成员等的对照表。

总结

在基础类库中使用了数据绑定库要配置混淆规则。

参考 proguard 混淆规则