Martin Zeitler
Martin Zeitler

Reputation: 76809

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?

Upvotes: 16

Views: 32178

Answers (13)

Supun Ayeshmantha
Supun Ayeshmantha

Reputation: 607

All the directories must be in simple letters , otherwise this error arises

example

package com.saw1993.mrep.activities.products

Upvotes: 1

Amos Banda
Amos Banda

Reputation: 21

rename your package to have all small letters, after changing my package from

"com.AmoTech.unischool" to "com.amotech.unischool"

, the errors disappeared and i was able to build without errors in android studio. image showing change of package

Upvotes: 0

Mohamed Mohamed Taha
Mohamed Mohamed Taha

Reputation: 172

If your package start capital letter change it to small it will fix the problem.

Upvotes: -1

Muhammad Noman
Muhammad Noman

Reputation: 2000

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.

Upvotes: 41

Shaheer Ghouri
Shaheer Ghouri

Reputation: 150

I my case I was using class name in small alphabets (propertyModel) should be (PropertyModel)

Upvotes: 0

Michel Fernandes
Michel Fernandes

Reputation: 1275

In my case it was just a incorrect path in the type variable XML file

<data>
        <variable
            name="clickListener"
            type="com.example.liberdade.caixa.CaixaListener" />

Upvotes: 1

JML
JML

Reputation: 721

Just in case nothing of the above works, check if the class type your referencing is in the same module or in a module on which the module where the xml is dependes.

Upvotes: 1

ravi
ravi

Reputation: 1001

A case where you will run into this error:

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

Empty type or undefined Type

Upvotes: 9

Behnam Nasehi
Behnam Nasehi

Reputation: 66

I got this error and it solved by changing the first letter of clickhandler class name to the capital I changed this: clickHandler to this: ClickHandler com.packagename.android.activity.AddAddressActivity.ClickHandler

Upvotes: 1

jee
jee

Reputation: 524

I have faced this issue because 1.my viewmodel classes was not extended from BaseObservable

  1. my package name starts with capital letter

Upvotes: 3

Martin Zeitler
Martin Zeitler

Reputation: 76809

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).

Upvotes: 10

Kolaaa
Kolaaa

Reputation: 256

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

Upvotes: 16

gtrevi
gtrevi

Reputation: 127

Same thing happening to me after updating to 3.2 (working application before the migration, and no code change)... then this "guess" issue even though I do have lowercase in the first letters of the package name!

<data>
   ...
   <variable name="rule" type="com.gta.viewmodels.vmRule"/>
   ...
</data>

So I "guess" your issue will still remain even after you update the package name (which is best practice anyways, given issues appear every single time I upgrade Android Studio!).

Anyway, I solved by downgrading the v2 databinding in gradle.properties (you'll get an "unsupported" warning, but just ignore it):

android.databinding.enableV2=false

Looks like the Android Studio PG hasn't tested that well this assertion (here):

Data Binding V2 is now enabled by default and is compatible with V1.

Upvotes: 5

Related Questions