108

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!

3
  • 1
    Seems like a bug, created issue: youtrack.jetbrains.com/issue/KT-17936 May 17, 2017 at 22:21
  • This bug appear even without any data binding. You just use 1.1.2-4 version of kotlin and apply plugin: 'kotlin-kapt'. Then you will get this error Error:Circular dependency between the following tasks: :app:compileDebugKotlin \--- :app:kaptDebugKotlin \--- :app:compileDebugKotlin () () - details omitted (listed previously)
    – Arsenius
    May 20, 2017 at 9:34
  • Also related issue: issuetracker.google.com/issues/38471980
    – BoD
    May 20, 2017 at 14:09

5 Answers 5

80

UPD: This was fixed for Android Gradle plugin 3.0.0-alpha3, in yout project root build.gradle, change the buildscript dependencies to use

classpath 'com.android.tools.build:gradle:3.0.0-alpha3'

This is actually a bug in the Kotlin Gradle plugin 1.1.2-4 inter-operation with the Android Gradle plugin 3.0.0-alpha1, caused by how the inputs and outputs of the tasks are set (and thus how the tasks are connected with the depends-on relation).

Thanks @VyacheslavGerasimov for creating the issue KT-17936.


As a temporary workaround, you can try to revert to Kotlin Gradle plugin 1.1.2-2 and disable incremental compilation:

In your project's root build.gradle, change the version of the Kotlin Gradle plugin:

buildscript {
    ...
    dependencies {
        ...
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-2'
    }
}

Add local.properties to the project root, with the following line:

kotlin.incremental=false

It is a known issue that the Kotlin Gradle plugin 1.1.2-2 and below crashes with the newest AGP versions, and disabling incremental compilation seems to fix that crash.

8
  • I believe you meant gradle.properties May 18, 2017 at 18:30
  • 1
    @LeandroBorgesFerreira, you use can any of them, because Gradle detects and interprets the local.properties file in your projects as well. Well, maybe local.properties is more suitable for local machine properties.
    – hotkey
    May 18, 2017 at 21:14
  • 1
    This leads to this error: stackoverflow.com/questions/44056104/…
    – gderaco
    May 19, 2017 at 9:44
  • 6
    Actually to revert to 1.1.2-3 also works fine. Same issue with Android Studio 2.3.2 and gradle 2.3.2 when using Kotlin 1.1.2-4 together with kotlin-kapt plugin
    – Arsenius
    May 20, 2017 at 9:37
  • 1
    @hotkey based on issuetracker.google.com/issues/38447344 this is an issue in the Android plugin, not kotlin gradle plugin. A fix was made and is planned to be released in the next 3.0.0 alpha release. May 24, 2017 at 18:56
41

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'
}
4
  • 1
    This is the correct answer, to add kotlin-kapt and that dependency line. The top answer isn't relevant any more Oct 29, 2017 at 13:45
  • Liked the use of the version variable
    – Shirane85
    Nov 16, 2017 at 12:58
  • I am getting: - with all versions [kapt] An exception occurred: java.lang.NullPointerException Sep 23, 2019 at 4:57
  • @PavelZaitsev I haven't used android studio in a while Sep 23, 2019 at 5:52
18

For those still looking for a proper solution, Google has already fixed this issue in Android Studio 3.0 Canary 3 build.

Friday, June 2, 2017

We have just released Android Studio 3.0 Canary 3 to the Canary and Dev Channels. The Android Gradle Plugin 3.0.0-alpha3 was also released through maven.google.com. This release has fixes to Gradle, Kotlin, and many other fixes. We continue to fix bugs in all areas of Studio 3.0 as we stabilize our features, so please continue to pass on feedback.

Working gradle configuration:

build.gradle (project)

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

build.gradle (module)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'


android {
    dataBinding.enabled = true
}
dependencies {
    kapt "com.android.databinding:compiler:3.0.0-alpha3"
}
4
  • How to fix this issue in Android Studio 2.3.2?
    – Arsenius
    Jun 6, 2017 at 5:07
  • You can use an older version of Kotlin plugin with incremental false. Check the previous answer by "hotkey" Jun 6, 2017 at 5:17
  • 1
    No, 1.1.2-4 still doesn't work. One still has to use 1.1.2-2 and also add kapt "com.android.databinding:compiler:3.0.0-alpha3" to your build.gradle (module) or you will get Unresolved reference: databinding.
    – 0leg
    Jun 8, 2017 at 8:27
  • Not fixed on 1.1.2-5 as well
    – Daivid
    Jun 14, 2017 at 2:11
4

If you use Kotlin Gradle plugin 1.3 and higher, you do not need to specify kapt "com.android.databinding:compiler:$plugin_version"

https://youtrack.jetbrains.com/issue/KT-32057

It is enough to specify dataBinding in your build.gradle file:

android {
    ...
    dataBinding {
        enabled = true
    }
}

or

android {
    ...
    buildFeatures {
        dataBinding true
    }
}
1
  • but you still get a warning, unless you add //noinspection DataBindingWithoutKapt
    – Raphael C
    Aug 14, 2023 at 14:54
0

in Android Studio Iguana | 2023.2.1 Patch 1 and gradle v8.7 for kotlin build.gradle.kts (project) add:

plugins {
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.jetbrainsKotlinAndroid) apply false
    kotlin("kapt") version "1.9.0"  apply false //add this line<don't tell anyone:)
}

and build.gradle.kts (app) add:

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsKotlinAndroid)
    id ("kotlin-kapt")// add this line

}

android {
...
    buildFeatures {
        compose = true
        viewBinding = true//this 
        dataBinding = true//and this add both!

    }
}

noting else need Just don't forget in xml must use data classs:

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="user"
            type="com.example.model.User" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{user.name}" />

    </LinearLayout>
</layout>

and in your activity:

// Get a binding instance for your layout
val binding: ActivityMainBinding =  DataBindingUtil.setContentView(this, R.layout.activity_main)
// Create a User object with data
val user = User("John")
// Set the user data on the binding variable
binding.user = user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.