3.1.0更新后,Android Studio无法生成数据绑定

Mar*_*vel 36 android android-studio android-studio-3.1

今天早上我做了android studio从3.0.1到3.1.0 的更新.更新gradle到最新版本后,我仍然遇到有关数据绑定的构建错误.

我的gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Run Code Online (Sandbox Code Playgroud)

我的所有错误都如下所示:

/Users/mp/Documents/GitHub/projectx/app/build/generated/source/dataBinding/baseClasses/Staging/debug/me/projectx/asdasd/databinding/GridItemActivityTypeBinding.java:57: error: cannot find symbol
      @Nullable DataBindingComponent component) {
                ^
  symbol:   class DataBindingComponent
  location: class GridItemActivityTypeBinding
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么我的数据绑定不会在android studio 3.1更新后生成?提前致谢

编辑1:忘了说,我试过清理/重建/无效缓存和重启/删除构建文件夹.

小智 19

在更新到Android Studio 3.2后,此行适用于我.我在我的项目中运行了Java和Kotlin代码(编译器).

将以下内容添加到gradle.properties:android.databinding.enableV2 = false

原因:

数据绑定V2

数据绑定V2现在默认启用,并与V1兼容.这意味着,如果您具有使用V1编译的库依赖项,则可以将它们与使用Data Binding V2的项目一起使用.但请注意,使用V1的项目不能消耗使用V2编译的依赖项.

来源(发行说明):https://developer.android.com/studio/releases/


小智 5

如果您在android studio 3.2上使用kotlin,请用此行替换distributionurl

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Run Code Online (Sandbox Code Playgroud)

然后系统会要求您将构建工具版本更改为适当的版本。完成此操作后,请从应用程序级别build.gradle文件中删除此行

kapt 'com.android.databinding:compiler:3.0.1
Run Code Online (Sandbox Code Playgroud)

并建立项目。它为我工作。


ste*_*ros 5

只是在graddle-wrapper.properties文件中注释这些行就帮助我解决了我的问题

#android.enableExperimentalFeatureDatabinding = true
#android.databinding.enableV2=true
Run Code Online (Sandbox Code Playgroud)


Mar*_*vel 2

好的,那些想知道我是如何解决这个问题的人。解决方案非常简单,但您可能不会喜欢它。

我必须将数据绑定中使用的所有类移至项目根包中,并在它再次开始工作后。

  • 这没有意义 (20认同)