androiddatabasekotlinandroid-roombuild-dependencies

Android Room - Unresolved reference: onConflictStrategy


Dao Interface Image

1

In this in the line @Insert(onConflict = onConflictStrategy.IGNORE) android studio says Unresolved reference: onConflictStrategy and in the line @Query("Select * from notes_table order by id ASC") The whole string is of green color while the words Select, from, order by and ASC should be orange Here is my build.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-kapt'
}

android {
    namespace 'com.example.scribbles'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.scribbles"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/atomicfu.kotlin_module'
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}
dependencies {
    implementation "androidx.appcompat:appcompat:1.6.1"
    implementation "androidx.activity:activity-ktx:1.6.1"

    // Dependencies for working with Architecture components
    // You'll probably have to update the version numbers in build.gradle (Project)

    // Room components
    implementation "androidx.room:room-runtime:2.5.0"
    implementation "androidx.room:room-ktx:2.5.0"
    kapt "androidx.room:room-compiler:2.5.0"
    androidTestImplementation "androidx.room:room-testing:2.5.0"

    // Lifecycle components
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.5.1"

    // Kotlin components
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"

    // UI
    implementation "androidx.constraintlayout:constraintlayout:2.1.4"
    implementation "com.google.android.material:material:1.8.0"

    // Testing
    testImplementation "junit:junit:4.13.2"
    androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
    androidTestImplementation ("androidx.test.espresso:espresso-core:3.4.0", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestImplementation "androidx.test.ext:junit:1.1.5"
}


package com.example.scribbles

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "notes_table")
class Note(@ColumnInfo(name = "text")val text:String) {
    @PrimaryKey(autoGenerate = true) var id = 0
}

I checked the dependencies version are up to date and imported androidx.room.OnconflictStrategy but it was saying unused import directive.


Solution

  • Change onConflictStrategy to OnConflictStrategy and yo'll be fine.