en80801
en80801

Reputation: 31

Unable to import Room database for use in Android app

I am working on developing an Android app through android studio and I am trying to implement a Room database. I was using https://developer.android.com/training/data-storage/room for instructions as well as https://medium.com/mindorks/using-room-database-android-jetpack-675a89a0e942, however I was unable to properly import it in. Trying import androidx.room.*; returns cannot resolve symbol 'room'. I was unable to find a solution to this issue.

I have tried:

Project Gradle File:

allprojects {
    repositories {
        jcenter()
        google()
    }
}        

App Gradle File:

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    def room_version = "2.2.6"
    implementation "android.arch.persistence.room:runtime:$room_version"
    annotationProcessor "android.arch.persistence.room:compiler:$room_version"
}        

Edit: I have also tried this without success, as well as using room_version as 1.0.0

def room_version = "2.2.6"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

Edit: While gradle syncing, I found that it got stuck on Download room-runtime-2.2.6.pom... for 10-15 minutes, and once it completed it showed the warnings:

Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.2.6.
Show Details
Affected Modules: app

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.room:room-runtime:2.2.6.
Show Details
Affected Modules: app

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.2.6.
Show Details
Affected Modules: app

Clicking show details did not direct it anywhere

Upvotes: 2

Views: 1913

Answers (1)

SpiritCrusher
SpiritCrusher

Reputation: 21043

You need to use androidx dependencies. you already using using androidx artifact so you have to use same for Room. Also its mentioned in docs.

def room_version = "2.2.6"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

Upvotes: 2

Related Questions