如何在Android Studio 3.0.0中使用数据绑定和Kotlin

问题描述:

我刚开始使用Android Studio 3.0.0,但是每次尝试构建项目时,都会出现此错误:

I just started to use Android Studio 3.0.0, but every time I try to build my project I get this error:

Error:Circular dependency between the following tasks:
:app:compileDebugKotlin
+--- :app:dataBindingExportBuildInfoDebug
|    \--- :app:compileDebugKotlin (*)
\--- :app:kaptDebugKotlin
     \--- :app:dataBindingExportBuildInfoDebug (*)
(*) - details omitted (listed previously)

我正在使用

kapt "com.android.databinding:compiler:2.2.0"

在我使用

androidProcessor "com.android.databinding:compiler:2.2.0"

它工作得很好...我做错了什么?

And it was working just fine... What I am doing wrong??

谢谢!

似乎您需要在模块级别的应用程序.gradle中添加3个gradle条目以添加数据绑定

It seems that you need 3 gradle entries in the app .gradle at module level to add data binding

  1. apply plugin: 'kotlin-kapt'
  2. android { ... dataBinding { enabled = true } }
  3. dependencies { ...... kapt "com.android.databinding:compiler:$compiler_version" }
  1. apply plugin: 'kotlin-kapt'
  2. android { ... dataBinding { enabled = true } }
  3. dependencies { ...... kapt "com.android.databinding:compiler:$compiler_version" }

请注意,我在项目级别的构建gradle中将编译器版本作为变量,以便可以在单个位置进行管理

Notice that I made compiler version a variable in the project level build gradle so it can be managed from a single place

默认值为:ext.kotlin_version = '1.1.3-2'

我添加了括号语法:

ext{
    kotlin_version = '1.1.3-2'
    compiler_version = '3.0.0-beta6'
}