skip to Main Content

I’m trying to configure the build.grade to use Room

The error persists:

Unresolved reference: room

And, consequently, the anotation remains Unresolved

@Entity

After 7 tutorials and 3 days, I have to surrender and ask for help.

Here I paste my build.grade. I’ve got it from this google tutorial:

https://developer.android.com/codelabs/android-room-with-a-view-kotlin#3

Which, by the way, is completely diferent from this other google tutorial:

https://developer.android.com/training/data-storage/room

What am I doing wrong?

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

}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.firewalker.mouth_conjugation"
        minSdk 21
        targetSdk 32
        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
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

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


}

dependencies {


    implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
    implementation "androidx.activity:activity-ktx:$rootProject.activityVersion"

    // 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-ktx:$rootProject.roomVersion"
    kapt "androidx.room:room-compiler:$rootProject.roomVersion"
    androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

    // Lifecycle components
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycleVersion"

    // Kotlin components
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"

    // UI
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
    implementation "com.google.android.material:material:$rootProject.materialVersion"

    // Testing
    testImplementation "junit:junit:$rootProject.junitVersion"
    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
    androidTestImplementation ("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"

}```



3

Answers


  1. Chosen as BEST ANSWER

    Thanks to Mike T and Dkathayat1, it worked. I had to set the correct versions.

    The code is the folowing:

    plugins {
        id 'com.android.application'
        id 'org.jetbrains.kotlin.android'
        id 'kotlin-kapt'
    
    }
    
    android {
        compileSdk 32
    
        defaultConfig {
            applicationId "com.firewalker.mouth_conjugation"
            minSdk 21
            targetSdk 32
            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
        }
        kotlinOptions {
            jvmTarget = '1.8'
        }
    
        packagingOptions {
            exclude 'META-INF/atomicfu.kotlin_module'
        }
    
    
    }
    
    dependencies {
    
    
        implementation "androidx.appcompat:appcompat:1.4.1"
        implementation "androidx.activity:activity-ktx:1.4.0"
    
        // 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-ktx:2.4.2"
        implementation 'androidx.room:room-common:2.4.2'
        kapt "androidx.room:room-compiler:2.4.2"
        androidTestImplementation "androidx.room:room-testing:2.4.2"
    
        // Lifecycle components
        implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
        implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.1"
        implementation "androidx.lifecycle:lifecycle-common-java8:2.4.1"
    
        // Kotlin components
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.30"
        api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
        api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
    
        // UI
        implementation "androidx.constraintlayout:constraintlayout:2.0.2"
        implementation "com.google.android.material:material:1.2.1"
    
        // Testing
        testImplementation "junit:junit:4.13.1"
        androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
        androidTestImplementation ("androidx.test.espresso:espresso-core:3.1.0", {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        androidTestImplementation "androidx.test.ext:1.1.2"
    
    
    }
    
    

  2. I have used these dependency for ROOM they worked find for me

    kapt "androidx.room:room-compiler:2.4.2"
    implementation "androidx.room:room-runtime:2.4.2"
    implementation "androidx.room:room-ktx:2.4.2"
    androidTestImplementation "androidx.room:room-testing:2.4.2"
    

    And these are the Plugins:

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

    }

    P.S it would had been great if you had shared the error code.

    Login or Signup to reply.
  3. Adding kotlin-dsl in plugins of module’s gradle file solved the issue for me.

    plugins { 'kotlin-dsl' }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search