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

当前回答

我也有同样的问题。在我的情况下,问题是关于数据库。我必须修改这行代码 @数据库(实体= [SearchedLocation::class, FavoriteLocation::class],版本= 1)

我在数据库中添加了另一个表,但忘记在上面的行中添加表。

其他回答

在我的案例中,降低kotlin版本(从1.4.21到1.3.21)解决了我的问题。

    buildscript { 
    ext.kotlin_version = '1.3.21'

    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
}

在升级到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")

在我的情况下,我解决它更新我的kotlin版本从1.3。X到1.6.0。

尝试用

kapt.use.worker.api=false 

在你的gradle里。属性设置文件

参考:https://youtrack.jetbrains.com/issue/kt - 40750

在某些情况下,这可能会有所帮助 gradle.properties

kapt.include.compile.classpath=true