数据绑定失败,并显示“无法猜测". [英] Data-Binding fails with "couldn't make a guess"
问题描述
由于更新了Android Studio 3.2.0
,因此我面临以下问题:
Since the update to Android Studio 3.2.0
I face the following issue:
任务':mobile:dataBindingGenBaseClassesDebug'的执行失败.
Execution failed for task ':mobile:dataBindingGenBaseClassesDebug'.
>无法猜测com.ACME.database.model.Order
> couldn't make a guess for com.ACME.database.model.Order
也看到了此 answer ,提示软件包名称必须以小写字母开头".
also seen this answer, which hints for that "package-names must start with a lower-case letter".
...看起来很像,似乎是variable
分配的原因:
... 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.
问:这样的分配也会受到该命名约定的影响吗?我的意思是,除了更改大写的包名之外,是否有任何可能使数据绑定v2成为猜测".锻炼吗?
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?
推荐答案
gradle.properties
中的这些设置确实启用了androidx
数据绑定编译器:
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
它抱怨:
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'
为了将Fragment
与默认的v2数据绑定编译器进行数据绑定,需要
最有可能是androidx.fragment.app.Fragment
而不是android.support.v4.app.Fragment
.这只是一个临时解决方案-但仍比还原到v1数据绑定编译器要好.
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.
更新:
由于com.android.tools.build:gradle:3.5.0
,上述解决方法不再起作用;必须重构XML文件.当不将任何class=""
属性添加到<data />
标记中并将此标记添加到任何现有的<layout>
标记中时,此方法效果最佳.在数据绑定的<include>
标签上重复的id
也可能会阻止生成(必须在<include>
标签上设置id
,而不是在包含的布局中).
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).
这篇关于数据绑定失败,并显示“无法猜测".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!