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

当前回答

我刚刚将Android Studio IDE更新到4.1.1版本,并得到了类似的问题。

我意识到……

在我没有一些*_Impl类之前(我知道它们在Kotlin的东西中),甚至没有一些新的*Tests类。

所以,在“运行所有的世界”之后,我做出了一个直观而公平的选择:我删除了我的“手工构建”包中的所有文件,这些文件在Android Studio更新之前并不存在。

你猜怎么着?

它工作。没有问题,关于kapt一点问题都没有。

我并不是说这是最终的解决方案。但它可以为你工作。

祝你过得愉快。

其他回答

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

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

如果你已经升级到类路径'com.android.tools.build:gradle:4.0.0' 替换之前的版本

dependencies {
    classpath 'com.android.tools.build:gradle:3.6.3'
}

和Change gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-   all.zip`

我有同样的问题与房间,我没有使用viewBinding。 我修复了它与使用exportSchema假在我的数据库类。

@Database(entities = [ModelClass::class], version = 1, exportSchema = false)
abstract class ModelDatabase: RoomDatabase() {}

记住:exportschemma可以根据你的用例而变化,通常它保持为假,所以我把它设置为假。

对我来说,问题是关于kotlin gradle插件。有时候android studio会自己更新kotlin gradle插件。回复gradle插件解决问题。

举个例子:

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"

:

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"

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