Data binding library errors caused by obfuscation

Summary of questions

AbstractMethodError: abstract method "androidx.databinding.ViewDataBinding androidx.databinding.DataBinderMapper.getDataBinder(androidx.databinding.DataBindingComponent, android.view.View, int)"

The stack is as follows:

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)

Scene appears

Encapsulates a class library, provides a encapsulated RecyclerAdapter, and uses DataBinding. Obfuscation is turned on when generating a class library, and an exception is thrown when using it.

Problem reason

Confuse Android x.databinding.databindingcomponent.

How to repair

Modify the confusion rule. Don't confuse this class.

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

Troubleshooting process

According to the error stack, this method can not be found. The initial suspicion is that the method has been confused, and then the test without confusion is used directly. There is no exception indeed. Confirmation is a matter of confusion.

Then, look at the mapping.txt file in the directory / build/outputs/mapping /. It is found that this kind of confusion is indeed true.

# compiler: R8
# compiler_version: 1.4.77
# min_api: 1
androidx.databinding.DataBindingComponent -> a.a.a:

mapping.txt provides a cross reference table of classes, methods, class members, etc. before and after confusion.

summary

The data binding library is used in the basic class library to configure obfuscation rules.

Reference resources Proguard confusion rule

End

Keywords: Android Java

Added by Kodak07 on Wed, 11 Dec 2019 16:05:30 +0200