android5-4 Exercise 1: Room setup ============================== // Room 2.x: module build.gradle.kts (versions are placeholders) plugins { id("com.google.devtools.ksp") version "" } dependencies { implementation("androidx.room:room-runtime:") ksp("androidx.room:room-compiler:") } import androidx.room.Entity import androidx.room.PrimaryKey @Entity(tableName = "notes") data class NoteEntity( @PrimaryKey(autoGenerate = true) val id: Long = 0, val text: String, val createdAt: Long = System.currentTimeMillis() ) import androidx.room.Dao import androidx.room.Delete import androidx.room.Insert import androidx.room.Query import kotlinx.coroutines.flow.Flow @Dao interface NoteDao { // A Flow: emits the list now and again whenever the table changes. Not suspend. @Query("SELECT * FROM notes ORDER BY createdAt DESC") fun observeNotes(): Flow> // One-shot writes are suspend functions @Insert suspend fun insert(note: NoteEntity) @Delete suspend fun delete(note: NoteEntity) @Query("DELETE FROM notes") suspend fun clearAll() } import androidx.room.Database import androidx.room.RoomDatabase @Database(entities = [NoteEntity::class], version = 1, exportSchema = false) abstract class AppDatabase : RoomDatabase() { abstract fun noteDao(): NoteDao } Where to find versions: the Room releases page (developer.android.com/jetpack/androidx/releases/room3 and the Room 2.x release notes) and the KSP releases on GitHub (the KSP version must match your Kotlin version). Choose one Room line first (see the table). If Room 3.0, switch imports to androidx.room3 and the artifacts to room3-runtime and room3-compiler (docs). Common errors (general knowledge): forgetting the ksp plugin or the ksp(...) compiler line; a KSP version that does not match Kotlin; a typo in an @Query column name. Code unrun.