数据绑定因“无法猜测"而失败

Data-Binding fails with quot;couldn#39;t make a guessquot;(数据绑定因“无法猜测而失败)
本文介绍了数据绑定因“无法猜测"而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

自从更新到 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).

这篇关于数据绑定因“无法猜测"而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)