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

其他回答

对我来说,一堆引用错误和DataBinding XML表达式中的一个错误产生了这个错误。

我在布局文件中删除了<variable/>,因为我想,我不再需要它了。我忘了在布局文件中引用了变量。

在构建项目之后,这会产生一个错误,其中不可能导入BindingImpl类,因为它不存在,并且此错误仅显示为与上述KaptExecution错误并行的警告。

搜索了一段时间后,我发现了这个错误并解决了它。然后,一堆引用错误显示,因为我重命名了一些东西,它没有重命名它在片段文件。在解决了这些错误之后,我完成了构建,没有出现错误或警告。

我有同样的错误一段时间,然后我开始检查其他包,我知道我在我的数据库代码中犯了一个打字错误。所以, “检查你的数据库和其他活动类文件,你可能会发现一些错误。”

当我将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

如果您正在使用Kotlin与Hilt

确保您已经注释了模块类

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

如果在布局中的绑定表达式中使用非英语字符,则会发生这种情况。例如:

<TextView ... android:text="@{ viewModel.letterTitle, default=`Важное письмо` }" />

如果执行“带——stacktrace选项运行”,就可以检查这种情况。如果stacktrace包含消息"MalformedByteSequenceException: 2字节UTF-8序列中的2字节无效。

布局包含非英文字符 或者某些源XML文件格式不正确