androidandroid-studiokotlinandroid-databindingandroid-studio-3.0

How to use Data Binding and Kotlin in 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)

I am using

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

Before I was using

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

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

Thanks!


Solution

  • 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" }

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

    default was: ext.kotlin_version = '1.1.3-2'

    I added with bracket syntax:

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