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

当前回答

是的,我也得到了这个错误,这也是一个房间相关的问题。

我已经定义了我的TypeConverters,但从未使用:@TypeConverters(TypeConverter.class)注释我的Room数据库。

其他回答

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

我也有同样的问题。让我带你们看一下我是如何解决这个问题的,以及我是如何解决它的,也许你们会有更大的了解。

之前解决

@Entity(tableName = "modules")
data class Module
(
    @PrimaryKey val id: Int,
    val name: String
)

@Entity(tableName = "sessions")
data class Session
(
    @PrimaryKey(autoGenerate = true) var id: Int,
    @ColumnInfo(name = "module_id") val moduleId: Int,
    @ColumnInfo(name = "start_time") val startTime: String,
    @ColumnInfo(name = "end_time") val endTime: String
)

data class ModuleSession
(
    @Embedded val module: Module,
    @Relation(
        parentColumn = "id",
        entityColumn = "module_id"
    )
    val sessions: List<Session>,
    @ColumnInfo(name = "is_updated") val isUpdated: Boolean = false // The problem
)

在DAO中

@Transaction
@Query("SELECT * FROM modules")
abstract suspend fun getModuleSession(): List<ModuleSession>

我得到的错误是

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

所以我深入挖掘,找到了下面的信息

The columns returned by the query does not have the fields [isUpdated] in com.gmanix.oncampusprototype.Persistence.ModuleSession even though they are annotated as non-null or primitive. Columns returned by the query: [id,name]
    public abstract java.lang.Object getModuleSession(@org.jetbrains.annotations.NotNull()

我从POJO ModuleSession中删除了字段IsUpdated,并将其添加到会话表中

后的变化

@Entity(tableName = "sessions")
data class Session
(
    @PrimaryKey(autoGenerate = true) var id: Int,
    @ColumnInfo(name = "module_id") val moduleId: Int,
    @ColumnInfo(name = "start_time") val startTime: String,
    @ColumnInfo(name = "end_time") val endTime: String,
    @ColumnInfo(name = "is_updated") val isUpdated: Boolean = false
)

data class ModuleSession
(
    @Embedded val module: Module,
    @Relation(
        parentColumn = "id",
        entityColumn = "module_id"
    )
    val sessions: List<Session>
)

另一方面,交叉检查SELECT语句中是否有可能导致问题的字段,或者您可以使用@Ignore对其进行注释

但是,如果你仍然觉得不舒服,你可以发布你的代码。

我希望这能有所帮助

在我的例子中,我添加了这一行

 android {
    .
    .
    .

    kapt.includeCompileClasspath = false

 }

如果你安装了新的kotlin插件(1.4.20-release-Studio4.1-1)并安装了dagger (kapt 'com.google.dagger:dagger-compiler:2.30'),也会出现这个问题。在这种情况下,一种解决方案可能是用视图绑定替换已弃用的插件:'kotlin-android-extensions' (https://developer.android.com/topic/libraries/view-binding)

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

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

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

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