Search code examples
androidkotlinandroid-roomkapt

Kapt exception (KaptExecution)


I'm working to add room to my project written in Kotlin but I always got this error.

Users data class

@Entity 
data class Users(

@PrimaryKey
val id: String? = "",

@ColumnInfo(name = "userFullName")
val name: String?,

@ColumnInfo(name = "userEmail")
val email: String?,
@ColumnInfo(name = "userPassword")
val password: String?,
@ColumnInfo(name = "userBDay", defaultValue = "")
val birthday: String?
)

UserDao

@Dao interface UserDao {

@Insert
fun insertUser(user: Users)

@Delete
suspend fun deleteUser(user: Users)

@Query("SELECT * FROM users")
fun getAllUsers(): List<Users>
}

User database

@Database(entities = [Users::class], version = 1)
abstract class UserDatabase : RoomDatabase() {
    abstract fun userDao(): UserDao

    companion object {
        @Volatile
        private var instance: UserDatabase? = null

        fun getUserDatabase(context: Context): UserDatabase {

            return instance ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    UserDatabase::class.java,
                    "usersDB"
                ).build()

                this.instance = instance
                instance
            }
        }
    }
}

Then when I build it, I got this error:

FAILURE: Build failed with an exception.

What went wrong:

2021-02-14T16:35:38.826+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]

Execution failed for task ':app:kaptDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.InvocationTargetException (no error message)

I got this error in every code I've written and downloaded from github.

I tried solutions in these links:

Repeated Build fails "To use Coroutine features, you must add `ktx`......."

How to get rid of Incremental annotation processing requested warning?

Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details

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

A failure occurred while executing com.android.build.gradle.internal.tasks

I also thought it could be caused by AS and I downloaded other version of AS, same thing happened


Solution

  • It was because of the android studio ide and kotlin version. So, when I updated the next version or downgraded to the other versions the problem's solved