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

前端 未结 30 1807
南旧
南旧 2020-12-12 20:01

All of sudden I start getting this error, and I am not getting idea why if anyone just let me know where this error is, will be enough helpful. As much I am able to get is t

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 20:43

    I had the same problem. Let me walk you through the example on how I ended up to the problem and the way I resolved it perhaps you can get a bigger picture.

    Before resolving

    @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,
        @ColumnInfo(name = "is_updated") val isUpdated: Boolean = false // The problem
    )
    

    In the DAO

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

    The error I got was

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

    So I dug deeper and found the below message

    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()
    

    I removed the field IsUpdated from the POJO ModuleSession and added it to the session table

    After changes

    @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
    )
    

    On the other hand crosscheck if there is any field on the SELECT statement that is a suspect causing issues or you can annotate it with @Ignore

    However you can post your code if you're still not comfortable.

    I hope that might help

提交回复
热议问题