Databinding NoSuchMethodError with buildtools 3.4.0
Asked Answered
G

1

7

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?

Ganja answered 16/1, 2019 at 16:49 Comment(4)
Do you have androidx in the project? The reason may be, that 3.4.0-alpha10 uses androidx for data binding and therefore crashes.Unessential
We are using androidx in this project.Ganja
I'm facing the same issue with an external library which uses data binding + AndroidX on 3.4.0-beta05 build tools. 3.3.1 works just fine.Stump
@JacobFerrero it will be fixed in 3.4.1Stump
S
12

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)

Stump answered 20/3, 2019 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.