I am working on an Android project using Room Database with Kotlin Symbol Processing (KSP), but I keep getting the following error when building my project:
[ksp] [MissingType]: Element 'com.example.notesapp.database.NoteDatabase' references a type that is not present
I have already checked my NoteDatabase and NoteDao, and they seem correctly implemented.
My Setup
NoteDatabase.ktpackage com.example.notesapp.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.notesapp.BuildConfig
import com.example.notesapp.model.Note
@Database(entities = [Note::class], version = BuildConfig.VERSION_CODE, exportSchema = false)
abstract class NoteDatabase : RoomDatabase() {
abstract fun getNoteDao(): NoteDao
companion object {
@Volatile
private var instance: NoteDatabase? = null
fun getInstance(context: Context): NoteDatabase {
return instance ?: synchronized(this) {
instance ?: createDatabase(context).also { instance = it }
}
}
private fun createDatabase(context: Context) =
Room.databaseBuilder(
context.applicationContext,
NoteDatabase::class.java,
"note_db"
)
.build()
}
}
NoteDao
package com.example.notesapp.database
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.example.notesapp.model.Note
@Dao
interface NoteDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertNote(note: Note)
@Update
suspend fun updateNote(note: Note)
@Delete
suspend fun deleteNote(note: Note)
@Query("SELECT * FROM NOTES ORDER BY id DESC")
fun getAllNotes(): LiveData<List<Note>>
@Query("SELECT * FROM notes WHERE noteTitle LIKE '%' || :query || '%' OR noteDesc LIKE '%' || :query || '%'")
fun searchNote(query: String?): LiveData<List<Note>>
}
Thanks for help