A Failure Occurred While Executing Org.Jetbrains.Kotlin.Gradle.Internal.Kaptexecution

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction?java.lang.reflect.Invocation?

I fixed it my problem by updating current kotlin version to latest version and moshi version to 1.12.0

I am facing this error A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

at first you have to use @TypeConverter from room because room can not insert the custom types like List or object or bitmap. So firstly make a class named converter then add this class in database using annotation @TypeConverters.
here is the code

Converter.kt

class Converter {
@TypeConverter
fun fromActor(actor: List<Actor>):String{
val type = object : TypeToken<List<Actor>>() {}.type
return Gson().toJson(actor,type)
}

@TypeConverter
fun toActor(actorString: String): List<Actor>{
val type = object : TypeToken<List<Actor>>() {}.type
return Gson().fromJson<List<Actor>>(actorString,type)
}
}

and finally add this converter.kt class in your database

MovieDatabase.kt

@Database(
entities = [Movie::class],
version = 1
)
@TypeConverters(Converter::class)
abstract class MovieDatabase : RoomDatabase() {
abstract fun getMovieDao(): MovieDao

companion object {
@Volatile
private var instance: MovieDatabase? = null
private val LOCK = Any()

operator fun invoke(context: Context) = instance
?: synchronized(LOCK) {
instance
?: buildDatabase(context).also {
instance = it
}
}

private fun buildDatabase(context: Context) = Room.databaseBuilder(
context.applicationContext,
MovieDatabase::class.java,
"movieDatabase"
).build()

}
}

Thank you.



Related Topics



Leave a reply



Submit