Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data-Binding fails with "couldn't make a guess"

Since the update to Android Studio 3.2.0 I face the following issue:

Execution failed for task ':mobile:dataBindingGenBaseClassesDebug'.

> couldn't make a guess for com.ACME.database.model.Order

also seen this answer, which hints for that "package-names must start with a lower-case letter".

... it seems alike, as if this variable assignment would be the cause:

<data class=".databinding.OrderFragmentBinding">
    <variable name="order" type="com.ACME.database.model.Order"/>
    ...
</data>

found: New data binding compiler for binding classes, which does not explain the change in behavior.

Q: are such assignments also affected by that naming convention? I mean, is there any chance (beside changing the uppercase package-name) to make that data-binding v2 "guess" work out?

like image 482
Martin Zeitler Avatar asked Sep 24 '18 23:09

Martin Zeitler


Video Answer


4 Answers

A case where you will run into this error:

<data>
    <variable
        name="something"
        type=""/>
</data>

Empty type or undefined Type

like image 120
ravi Avatar answered Oct 12 '22 16:10

ravi


Its because of your class name or package name which use databinding. These classes( which use databinding) has to started with capital letter and packages started with lowercase.

like image 32
Muhammad Noman Avatar answered Oct 12 '22 17:10

Muhammad Noman


Had a similar problem. Solved by renaming the data class by starting with capital letters.

like image 14
Kolaaa Avatar answered Oct 12 '22 16:10

Kolaaa


these settings in the gradle.properties do enable the androidx data-binding compiler:

android.databinding.enableV2 = false
android.enableExperimentalFeatureDatabinding = true

one can see that by the fetched package:

Download https://dl.google.com/dl/android/maven2/androidx/databinding/databinding-compiler/3.2.0/databinding-compiler-3.2.0.pom
Download https://dl.google.com/dl/android/maven2/androidx/databinding/databinding-compiler/3.2.0/databinding-compiler-3.2.0.jar

and it complains:

WARNING: The option setting 'android.databinding.enableV2=false' is experimental and unsupported.
The current default is 'true'

WARNING: The option setting 'android.enableExperimentalFeatureDatabinding=true' is experimental and unsupported.
The current default is 'false'

most likely androidx.fragment.app.Fragment instead of android.support.v4.app.Fragment would be required, in order to data-bind a Fragment with the default v2 data-binding compiler. this is also just a temporary solution - but still better than to revert to the v1 data-binding compiler.


Update:

Since com.android.tools.build:gradle:3.5.0 the above workaround does not work anymore; One has to refactor the XML files. It works best when not adding any class="" attribute into the <data /> tag - and also adding this tag into any existing <layout> tag. Duplicate id on data-bound <include> tags may also prevent the generation (the id has to be set on the <include> tag, not in the included layout).

like image 10
Martin Zeitler Avatar answered Oct 12 '22 17:10

Martin Zeitler