Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Databinding NoSuchMethodError with buildtools 3.4.0

When using the latest DataBinding

classpath 'com.android.tools.build:gradle:3.4.0-alpha10'

A NoSuchMethodError crashes the app upon Activity load. Using:

classpath 'com.android.tools.build:gradle:3.2.1'

causes the databinding to work successfully.

Here's the crash:

java.lang.NoSuchMethodError: No direct method <init>
(Landroidx/databinding/DataBindingComponent;Landroid/view/View;I)V in 
class Landroidx/databinding/ViewDataBinding; or its super classes
(declaration of 'androidx.databinding.ViewDataBinding'

Is there any way around this if we want to use the latest build tools?

like image 560
Jacob Ferrero Avatar asked Jan 16 '19 16:01

Jacob Ferrero


1 Answers

One of your libraries relies on data binding and is distributed with generated data-binding classes built with build tools 3.3 (or earlier). The issue is caused by the breaking change introduced in the latest beta/rc version of the data binding lib. In version 3.4 the signature of androidx.databinding.ViewDataBinding constructor has been changed from:

protected ViewDataBinding(DataBindingComponent bindingComponent, View root, int localFieldCount)

to:

protected ViewDataBinding(Object bindingComponent, View root, int localFieldCount)

Which makes any generated data binding class binary incompatible with 3.4 databinding lib, resulting in the following exception upon startup:

java.lang.NoSuchMethodError: No direct method <init>(Landroidx/databinding/DataBindingComponent;Landroid/view/View;I)V in class Landroidx/databinding/ViewDataBinding; or its super classes (declaration of 'androidx.databinding.ViewDataBinding' appears in /data/app/com.example.idolon-LqF2y8dUMxZoK3PVRlzbzg==/base.apk)
        at com.example.lib.databinding.ActivityLibBinding.<init>(ActivityLibBinding.java:20)
        at com.example.lib.databinding.ActivityLibBindingImpl.<init>(ActivityLibBindingImpl.java:30)
        at com.example.lib.databinding.ActivityLibBindingImpl.<init>(ActivityLibBindingImpl.java:27)
        at com.example.lib.DataBinderMapperImpl.getDataBinder(DataBinderMapperImpl.java:316)
        at androidx.databinding.MergedDataBinderMapper.getDataBinder(MergedDataBinderMapper.java:74)
        at androidx.databinding.DataBindingUtil.bind(DataBindingUtil.java:199)
        at androidx.databinding.DataBindingUtil.bindToAddedViews(DataBindingUtil.java:327)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:306)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)

As a workaround you can rebuild libraries that contains data binding classes using the latest build tools.

The corresponding bug on Androig Bug tracker is: https://issuetracker.google.com/issues/122936785

UPDATE
The issue has been fixed and the fix is available in 3.5 beta 1 (it will also be available in the upcoming 3.4.1)

like image 140
Idolon Avatar answered Sep 30 '22 15:09

Idolon