Search code examples
androidkotlinandroid-sqliteandroid-room

android studio not recognizing(change in color) and suggesting SQLite commands in room @Query() annotation


Student.kt

@Entity(tableName = "student_table")
data class Student(
    @PrimaryKey(autoGenerate = true) val id:Int?,
    @ColumnInfo(name = "first_name") val firstName:String?,
    @ColumnInfo(name = "last_name") val lastName:String?,
    @ColumnInfo(name = "roll_no") val rollNo:Int?
)

StudentDao.kt

@Dao
interface StudentDao {

    @Query("SELECT * FROM student_table")
    fun getAll(): List<Student>

    @Query("SELECT * FROM student_table WHERE roll_no LIKE :roll LIMIT 1")
    suspend fun findByRoll(roll: Int): Student

Build Output(31 tasks were UP-TO-DATE, i didn't mentioned them below)

> Task :app:createDebugVariantModel UP-TO-DATE
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:processDebugMainManifest
> Task :app:processDebugManifest
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:mergeDebugNativeLibs NO-SOURCE
> Task :app:stripDebugDebugSymbols NO-SOURCE
> Task :app:processDebugManifestForPackage
> Task :app:processDebugResources
> Task :app:packageDebug
> Task :app:createDebugApkListingFileRedirect
> Task :app:assembleDebug


BUILD SUCCESSFUL in 1m 19s
37 actionable tasks: 6 executed, 31 up-to-date

Build Analyzer results available

In StudentDao.kt file @Query() annotation not recognizing SQLite query ex. student_table(as table name) & not highlighting SQLite queries like SELECT.


Solution

  • i solved this problem by trying different versions of room. previously i was using latest version which was 2.5.0 as of march 2023

    def room_version = "2.4.0"
    implementation "androidx.room:room-runtime:$room_version"
    ksp "androidx.room:room-compiler:$room_version"
    implementation "androidx.room:room-ktx:$room_version"