Android Kotlin - Room Local Storage, build error "A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution"

Viewed 10241

[Using Gradle 4.0.0], I try to implement local storage by room in Android Kotlin in Andriod Studio 4. When I try to build project, i meet an error in build console

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

Image:

enter image description here

Gradle:

apply plugin: 'kotlin-kapt'

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" 

Please kindly help to show the solution for me

6 Answers

Android Studio's UI was just hiding the error...

when the error occurred, it highlighted the item in the list view, and showed an unhelpful message in the terminal view. bad bad

to find the real error, select the root item in the list view so that Android Studio would display the whole build output in the terminal view, then scroll to find error. good good

The error is show by the kapt in your project, and to show full error message you will have to add these to your gradle.properties file.

kapt.use.worker.api=false
kapt.incremental.apt=false

After that run your app again, and try to read from the detailed error.

kapt error image

Verify your DAO, make sure everything is where it is supposed to be. 4/5 when I get this error, I find out I miswrote/forgot something somewhere with the dao

I was getting the same error, when i was trying to retrieve all the columns from db with return type of LiveData array list(Dao file), eg: return type was -

LiveData<ArrayList<Book>>

And when i change ArrayList to list like this: LiveData<List<Book>>

Although i'm not sure about the cause or reason for the error, the above chnages worked for me

also,

If you are using coroutines, check the room dependency for room-ktx

If you have Hilt in your project with Kotlin, make sure you have annotated your module class with:

@Module
@InstallIn(SingletonComponent::class)

I was getting an error because I haven't mentioned the my DAO() class

@Database(entities = [Products::class], version = 1, exportSchema = false) abstract class LocalDatabase : RoomDatabase(){

abstract fun productDao(): ProductDao() // I missed this line


companion object{

    @Volatile
    private var INSTANCE :LocalDatabase ?=null

    fun getDatabase(context: Context):LocalDatabase{

        val tempInstance = INSTANCE
        if (tempInstance != null)
            return tempInstance

        synchronized(this) {
            val instance = Room.databaseBuilder(
                context.applicationContext,
                LocalDatabase::class.java,
                "Zenex"
            ).build()
            INSTANCE = instance
            return instance
        }
    }
}





override fun createOpenHelper(config: DatabaseConfiguration?): SupportSQLiteOpenHelper {

    TODO("Not yet implemented")

}

override fun createInvalidationTracker(): InvalidationTracker {
    TODO("Not yet implemented")
}

override fun clearAllTables() {

}

}

Related