Home > OS >  Android Studio Kotlin Room database error
Android Studio Kotlin Room database error

Time:12-30

While running my application I get this error (as well as 6 other similar errors) and changing the room version in my code to 2.3.0 or 2.2.3 doesn't fix it.

1: Task failed with an exception.

  • What went wrong: Execution failed for task ':app:checkDebugAarMetadata'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find androidx.room:room-coroutines:2.4.0. Searched in the following locations: - https://dl.google.com/dl/android/maven2/androidx/room/room-coroutines/2.4.0/room-coroutines-2.4.0.pom - https://repo.maven.apache.org/maven2/androidx/room/room-coroutines/2.4.0/room-coroutines-2.4.0.pom - https://jcenter.bintray.com/androidx/room/room-coroutines/2.4.0/room-coroutines-2.4.0.pom Required by: project :app

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Here is my Project Build.Gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.5.31'


    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

ext {
    activityVersion = '1.4.0'
    appCompatVersion = '1.4.0'
    constraintLayoutVersion = '2.1.2'
    coreTestingVersion = '2.1.0'
    coroutines = '1.5.2'
    lifecycleVersion = '2.4.0'
    materialVersion = '1.4.0'
    roomVersion = '2.4.0'
    // testing
    junitVersion = '4.13.2'
    espressoVersion = '3.4.0'
    androidxJunitVersion = '1.1.3'
}


task clean(type: Delete) {
    delete rootProject.buildDir
}

Here is my app Build.Gradle:

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

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.burnouttracker"
        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'
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

}

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"
    implementation("androidx.room:room-runtime:$rootProject.roomVersion")
    kapt "androidx.room:room-compiler:$rootProject.roomVersion"
    androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
    //I added this one
    implementation "androidx.room:room-coroutines:$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"




    //implementation 'androidx.core:core-ktx:1.7.0'
    //implementation 'androidx.appcompat:appcompat:1.4.0'
    //implementation 'com.google.android.material:material:1.4.0'
    //implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    //testImplementation 'junit:junit:'
    //androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    //androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

CodePudding user response:

I see you've commented room-ktx and added the room-coroutine

From room Version 2.1.0-alpha05 the artifact room-coroutines has been renamed to room-ktx following the same naming as other androidx artifacts.

So please use room-ktx instead of room-coroutines

//...

//room dependencies
implementation "androidx.room:room-ktx:$$rootProject.roomVersion"
implementation "androidx.room:room-runtime:$$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

//...
  • Related