問題描述
自從更新到 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).
這篇關于數據綁定因“無法猜測"而失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!