问题描述
自从更新到 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
也看到了这个答案,提示包名必须以小写字母开头".
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'
很可能需要 androidx.fragment.app.Fragment
而不是 android.support.v4.app.Fragment
,以便数据绑定 Fragment
使用默认的 v2 数据绑定编译器.这也只是一个临时解决方案 - 但仍然比恢复到 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
也可能会阻止生成(必须在 < 上设置
标签,不在包含的布局中).id
;include>
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).
这篇关于数据绑定因“无法猜测"而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!