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

当前回答

大声喊出上面@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
        }
}

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

其他回答

解决了只需增加gradle版本到最新

它在项目级别的gradle文件中,在dependencies块下。

classpath "com.android.tools.build:gradle:4.x.x"

改变

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"

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

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

当我将ROOM添加到我的应用程序(Kotlin)时,我也遇到了同样的问题。 我花了很长时间才发现问题所在,最后才发现我是在用下面的方法给我的应用程序添加ROOM。

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

所以我把上面两行换成了下面的,摆脱了痛苦。

    def room_version = "2.2.6"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

如果对你有帮助,点击向上键:D

在我的情况下,我忘记在实体类中添加@PrimaryKey。