8

[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

Bong Channarith
  • 241
  • 1
  • 2
  • 10
  • Can you post more details from the error output? Something like that shown in [this similar question](https://stackoverflow.com/q/62131564/4815718). – Bob Snyder Jun 11 '20 at 21:24
  • 3
    This happened to me just now. The solution was to take a look at my @Query annotations for syntax errors in SQL queries. Once I fixed them, the kapt error went away and the app built successfully. – Eli Connelly Jun 11 '20 at 22:13
  • 1
    I had the same problem recently and i realized that I had not added the entity classes as part of the database `@Database(entities = [ ProductEntityOne::class, ProductEntityTwo::class])` – chikwapuro Jun 25 '20 at 14:21
  • I am facing the same issue. The solutions posted here didn't work for me.You got any solution? – Priyabrata Jul 10 '20 at 13:49
  • I had similar error and found the issue and fixed it. You might have done a similar error. https://stackoverflow.com/questions/63133657/after-adding-kapt-plugin-a-failure-occurred-while-executing-org-jetbrains-kotl/63139756#63139756 – Mustaqode Jul 28 '20 at 17:36

6 Answers6

13

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

Eric
  • 16,397
  • 8
  • 68
  • 76
3

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

Sreekant Shenoy
  • 1,420
  • 14
  • 23
2

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

Koch
  • 555
  • 4
  • 15
1

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

1

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

@Module
@InstallIn(SingletonComponent::class)
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Thiago
  • 12,778
  • 14
  • 93
  • 110
  • Can you please help me on it..I am using the hilt with my java andorid and getting this following exception `java.lang.reflect.InvocationTargetException (no error message)` ..Please help me – Ravindra Kushwaha May 30 '21 at 09:51
0

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

}

}