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

时间:2021-12-10 20:55:14

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

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

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!

谢谢!

4 个解决方案

#1


11  

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

您似乎在模块级别的app .gradle中需要3个gradle条目来添加数据绑定

  1. apply plugin: 'kotlin-kapt'
  2. 申请插件:'kotlin-kapt'
  3. android { ... dataBinding { enabled = true } }
  4. android {... dataBinding {enabled = true}}
  5. dependencies { ...... kapt "com.android.databinding:compiler:$compiler_version" }
  6. 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

请注意,我在项目级构建gradle中使编译器版本成为变量,因此可以从单个位置进行管理

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

默认是: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'
}

#2


78  

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

UPD:这是针对Android Gradle插件3.0.0-alpha3修复的,在你的项目root build.gradle中,更改了要使用的buildscript依赖项

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).

这实际上是Kotlin Gradle插件1.1.2-4与Android Gradle插件3.0.0-alpha1互操作的一个错误,这是由任务的输入和输出设置的方式(以及因此任务如何连接)引起的依赖关系)。

Thanks @VyacheslavGerasimov for creating the issue KT-17936.

感谢@VyacheslavGerasimov创建问题KT-17936。


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

作为临时解决方法,您可以尝试恢复为Kotlin Gradle插件1.1.2-2并禁用增量编译:

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

在项目的root build.gradle中,更改Kotlin Gradle插件的版本:

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

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

将local.properties添加到项目根目录,使用以下行:

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.

Kotlin Gradle插件1.1.2-2及以下版本与最新的AGP版本崩溃是一个众所周知的问题,禁用增量编译似乎可以解决这个崩溃问题。

#3


17  

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

对于那些仍在寻找合适解决方案的人来说,谷歌已经在Android Studio 3.0 Canary 3版本中解决了这个问题。

Friday, June 2, 2017

2017年6月2日星期五

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.

我们刚刚向Canary和Dev Channels发布了Android Studio 3.0 Canary 3。 Android Gradle Plugin 3.0.0-alpha3也是通过maven.google.com发布的。此版本修复了Gradle,Kotlin和许多其他修复程序。我们继续修复Studio 3.0的所有区域中的错误,因为我们稳定了我们的功能,所以请继续传递反馈。

Working gradle configuration:

工作gradle配置:

build.gradle (project)

build.gradle(项目)

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)

build.gradle(模块)

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


2  

I have recenly write Blog for Data Binding android with Kotlin here

我已经在这里与Kotlin一起写了Blog for Data Binding android

Use Classpath

使用Classpath

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

Dependency

依赖

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

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

dependencies {
    ......
    kapt 'com.android.databinding:compiler:2.3.1'
}

for more detail check out this post

有关更多详细信息,请查看此帖子

#1


11  

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

您似乎在模块级别的app .gradle中需要3个gradle条目来添加数据绑定

  1. apply plugin: 'kotlin-kapt'
  2. 申请插件:'kotlin-kapt'
  3. android { ... dataBinding { enabled = true } }
  4. android {... dataBinding {enabled = true}}
  5. dependencies { ...... kapt "com.android.databinding:compiler:$compiler_version" }
  6. 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

请注意,我在项目级构建gradle中使编译器版本成为变量,因此可以从单个位置进行管理

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

默认是: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'
}

#2


78  

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

UPD:这是针对Android Gradle插件3.0.0-alpha3修复的,在你的项目root build.gradle中,更改了要使用的buildscript依赖项

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).

这实际上是Kotlin Gradle插件1.1.2-4与Android Gradle插件3.0.0-alpha1互操作的一个错误,这是由任务的输入和输出设置的方式(以及因此任务如何连接)引起的依赖关系)。

Thanks @VyacheslavGerasimov for creating the issue KT-17936.

感谢@VyacheslavGerasimov创建问题KT-17936。


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

作为临时解决方法,您可以尝试恢复为Kotlin Gradle插件1.1.2-2并禁用增量编译:

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

在项目的root build.gradle中,更改Kotlin Gradle插件的版本:

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

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

将local.properties添加到项目根目录,使用以下行:

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.

Kotlin Gradle插件1.1.2-2及以下版本与最新的AGP版本崩溃是一个众所周知的问题,禁用增量编译似乎可以解决这个崩溃问题。

#3


17  

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

对于那些仍在寻找合适解决方案的人来说,谷歌已经在Android Studio 3.0 Canary 3版本中解决了这个问题。

Friday, June 2, 2017

2017年6月2日星期五

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.

我们刚刚向Canary和Dev Channels发布了Android Studio 3.0 Canary 3。 Android Gradle Plugin 3.0.0-alpha3也是通过maven.google.com发布的。此版本修复了Gradle,Kotlin和许多其他修复程序。我们继续修复Studio 3.0的所有区域中的错误,因为我们稳定了我们的功能,所以请继续传递反馈。

Working gradle configuration:

工作gradle配置:

build.gradle (project)

build.gradle(项目)

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)

build.gradle(模块)

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


2  

I have recenly write Blog for Data Binding android with Kotlin here

我已经在这里与Kotlin一起写了Blog for Data Binding android

Use Classpath

使用Classpath

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

Dependency

依赖

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

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

dependencies {
    ......
    kapt 'com.android.databinding:compiler:2.3.1'
}

for more detail check out this post

有关更多详细信息,请查看此帖子