Data-Binding fails with “couldn't make a guess”

感情迁移 提交于 2019-12-01 11:55:23

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

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.

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

Its because of you class name or package name which use databinding. These class( which use databinding) have to start with capital word and packages start with lowercase.

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

  1. my package name starts with capital letter
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!