突然我开始得到这个错误,我不知道为什么如果有人告诉我这个错误在哪里,就足够有帮助了。正如我所能得到的,这是因为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

当前回答

在经历了许多痛苦之后,我决定尝试annotationProcessor而不是kapt,希望它至少可以显示错误消息或任何可以帮助我定位源代码的东西。但幸运的是(或不幸的是;由于浪费了时间),它成功地建立了,没有任何错误。 这主要是kapt本身的一个bug。所以,试试这个方法,它可能会有帮助。

其他回答

什么都没用,我试了所有的方法,最后发现一个小错误造成了一个大问题。

返回到每个新创建的数据库文件,逐行仔细检查每个文件的代码。

检查Database类,检查Dao是否声明,例如,

abstract val commentDatabaseDao: CommentDatabaseDao

声明为val而不是var,这是在我的情况下,最终为这个解决。

是的,我也得到了这个错误,这也是一个房间相关的问题。

我已经定义了我的TypeConverters,但从未使用:@TypeConverters(TypeConverter.class)注释我的Room数据库。

大声喊出上面@Rene Spies的回答,我在使用数据绑定时也得到了这个错误。当您将@Bindable注释放在Kotlin中数据类的主构造函数的字段上时,构建引擎不喜欢这样做。

所以不要做下面的事情,

data class MyAwesomePojo(
    @Bindable
    var firstname: String,
    var lastname: String
)

相反,你需要做的是

data class MyCorrectAwesomePojo(
    var lastname: String
):{
    @get:Bindable
    var firstname: String
        set(value){
            field = value
        }
}

好处:如果你像我一样试图使用双向绑定来防止设置和获取的无限循环,请记得在设置值到字段之前检查相同的值。

在我的情况下,我使用房间和我的一个databasDao方法有一个未使用的参数,不幸的是android工作室没有正确地警告我

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