14

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?

Community
  • 1
  • 1
Martin Zeitler
  • 1
  • 19
  • 155
  • 216

13 Answers13

39

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.

Muhammad Noman
  • 1,842
  • 19
  • 14
16

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

Kolaaa
  • 248
  • 3
  • 6
10

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

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
9

A case where you will run into this error:

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

Empty type or undefined Type

ravi
  • 899
  • 8
  • 31
5

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.

gtrevi
  • 97
  • 1
  • 8
  • thanks for the input, but found a better temporary solution. might refactor to `androidx`, because I have the outdated `support-v4` library under suspicion, which provided that `Fragment` class. – Martin Zeitler Sep 25 '18 at 00:45
  • Great Answer! Today i also upgraded AS 3.2, and facing same issue, Illegal Arguments Exception “couldn't make a guess for”. Thanks @gtrevi. – Dhiren Basra Sep 25 '18 at 15:21
  • @Dhiren my answer extends on this. while disabling data-binding v2 is not the answer, that is hiding the problem (I could as well as have reverted to build-tools `3.1.4`, with exactly the same effect). if it would have been the answer, I would have accepted it, instead adding another one. – Martin Zeitler Sep 25 '18 at 16:31
  • I absolutely agree that mine is not a solution, but a quick workaround (as the other extension Martin suggested) just to bust Yet Another Build-Braking Change for whom "dares" to upgrade this IDE. Both should be used temporarily to move forward while adapting to the new, instead of a big-bang refactoring or tool regression (therefore the least changes the better in my opinion). The real problem is the Android Studio PG, when it claims that "Data Binding V2 is now enabled by default and is compatible with V1" whereas it is not, since you need to change your code! – gtrevi Sep 25 '18 at 19:00
  • @MartinZeitler you are using outdated `support-v4`, but I am not, i am using everything new, but still getting “couldn't make a guess”, by updaing AS 3.2. as you said by disabling data-binding v2 is not the answer and that is hiding the problem, tell me what the correct solution for that ? @gtrevi if its quick workaround or temporary solution, let me know what can i do to get a rid from this warning ? `WARNING: The option setting 'android.databinding.enableV2=false' is experimental and unsupported.` – Dhiren Basra Sep 27 '18 at 06:53
  • `android.databinding.enableV2 = false` and `android.enableExperimentalFeatureDatabinding = true` I have added this 2 lines in `gradle.properties` file for a quick solution. but warnings still appeared. – Dhiren Basra Sep 27 '18 at 06:57
  • @Dhiren both of these answers are workarounds, this one is switching back to v1 and mine is switching to v2 androidx; you need to clean your project and/or delete the build directory, to get rid of the previously generated data-bindings. – Martin Zeitler Sep 27 '18 at 06:58
  • @MartinZeitler You mean I must have to switching to v2 androidX. to get rid from `couldn't make a guess` error in AS 3.2, and remove `android.databinding.enableV2 = false` from `gradle.properties` ? – Dhiren Basra Sep 27 '18 at 07:12
  • @Dhiren, yes... that's what's in my point above: welcome to Android Studio upgrades. To get the rid of the warning, you need to move to the new, and if you want to know how and why, I'd ask the Android Studio PG (google forum) since they claim _V2 to be backward compatible with V1_, whereas it is not, and they haven't even provided migration guidance/support. I don't plan to move to androidX soon, but when I'll do, happy to support/post hints. – gtrevi Sep 27 '18 at 16:51
3

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

  1. my package name starts with capital letter
jee
  • 524
  • 4
  • 7
1

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

Behnam Nasehi
  • 56
  • 1
  • 5
1

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.

JML
  • 611
  • 3
  • 9
1

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" />
Michel Fernandes
  • 1,187
  • 9
  • 8
0

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

0

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

Amos Banda
  • 11
  • 1
0

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

example

package com.saw1993.mrep.activities.products
Supun Ayeshmantha
  • 499
  • 1
  • 5
  • 9
-1

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