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

当前回答

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

其他回答

改变

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"

以我为例:问题解决了

步骤:

删除viewModel变量-在XML中。

<variable
    name="viewModel"
    type="com.xx.AppViewModel" / >

删除了所有viewModel绑定引用-在XML中。

android:text="@{viewModel.simName}"

删除了对绑定映射- In活动的viewModel实例引用

binding.viewModel = viewModel

清理项目并重新编译。 在XML & Build项目中添加viewModel变量。

< variable
    name="viewModel"
    type="com.xx.AppViewModel" / >

将viewModel实例引用添加到绑定映射-在活动和构建项目中

binding.viewModel = viewModel

添加所有viewModel绑定引用-在XML & Build项目中..

    android:text="@{viewModel.simName}"

它现在可以工作了。

——我希望这对你也有用。

我是在将Android Studio升级到Arctic Fox(2020.3.1)后开始遇到这种情况的。

我通过将JDK版本从1.8更新到Embedded JDK来解决这个问题。

修改JDK。

在Android Studio中打开项目,选择文件>设置…>构建,执行,部署>构建工具> Gradle 在Mac: Android Studio >首选项…>构建,执行,部署>构建工具> Gradle。 在Gradle JDK下,选择嵌入式JDK选项。

正如这里提到的

在我的情况下,我只是重命名/settings.gradle中的rootProject.name 我再次重复这个动作,它的工作..我不明白为什么会发生这种事,但我希望这能帮助到其他人,节省他们的时间

如果您正在使用Kotlin与Hilt

确保您已经注释了模块类

@Module
@InstallIn(SingletonComponent::class)
class AppModule {
//...
}