突然我开始得到这个错误,我不知道为什么如果有人告诉我这个错误在哪里,就足够有帮助了。正如我所能得到的,这是因为android studio的新更新。 我得到的错误的详细总结。

Task :app:kaptDebugKotlin
    ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1C:\Users\shubh\Downloads\MarginCalculator\app\build\generated\source\kapt\debug\com\kotlin_developer\margincalculator\DataBinderMapperImpl.java:10: error: cannot find symbol
    import com.kotlin_developer.margincalculator.databinding.FragmentCalculatorScreenBindingImpl;

    symbol:   class FragmentCalculatorScreenBindingImpl

    Task :app:kaptDebugKotlin FAILED
    location: package com.kotlin_developer.margincalculator.databinding
    FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 17s
29 actionable tasks: 27 executed, 2 up-to-date

当前回答

在我的情况下,我使用协程,但我忘记添加Kotlin扩展和协程支持的房间

Def room_version = "2.2.6" 实现“androidx.room: room-ktx: room_version美元”

其他回答

我有一个枚举在我的实体属性使用房间。经过长时间的搜索,导致如下失败。

“:app:kaptDebugKotlin”任务执行失败。 执行org.jetbrains.kotlin.gradle.internal.KaptExecution时发生失败 invocationtargetexception(没有错误消息)

enum class Color{RED,BLACK,BLUE,GREEN,WHITE}
@Entity(tableName = "flower_table")
data class Flower(
        @PrimaryKey(autoGenerate = true) val id: Int,
        @ColumnInfo(name = "name") val name: String,
        @ColumnInfo(name = "color") val color: Color)

val flower = Flower(2, "rose", Color.RED)

我的解决方案是在实体属性中使用枚举的索引。

@Entity(tableName = "flower_table")
data class Flower(
        @PrimaryKey(autoGenerate = true) val id: Int,
        @ColumnInfo(name = "name") val name: String,
        @ColumnInfo(name = "color") val color: Int)

val flower = Flower(4, "tulip", Color.BLUE.ordinal)

希望能对你有所帮助! PS,不要忘记更新数据库类中的版本号。

@Database(entities = [Flower::class], version = 2)
abstract class FlowerRoomDatabase : RoomDatabase() {

在升级到kotlin_version = '1.4.31'(从1.3.71)时得到完全相同的错误

以下moshi升级修复了我的问题:

implementation("com.squareup.moshi:moshi:1.11.0")
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.11.0")

有趣的是,我得到这个错误是因为我添加了Retrofit的描述。注意不要混淆“房间”和“改造”的描述。

改变

implementation "android.arch.persistence.room:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"

来 (更新4 -2021年9月)

 implementation "androidx.room:room-runtime:2.3.0"
 annotationProcessor "androidx.room:room-compiler:2.3.0"

好吧,如果你使用Android Studio 4.1.2,这个问题也会发生。

所以,你要做的是:

下载jdk 11(搜索下载) 在Android Studio中,点击“文件->项目结构-> Jdk位置->更改到刚刚下载的Jdk的路径。