androidkotlingradleandroid-room

room and kotlinx coroutines use different versions of org.jetbrains:annotations which causes my project build to fail


basically what i said in the title, the org.jetbrains:annotations versions conflict between the two depedencies.

roomcompiler = { module = "androidx.room:room-compiler", version.ref = "room" }

the output of the ' ./gradlew :app:dependencies --configuration debugRuntimeClasspat' command is available here: https://sharetext.io/148140a7

here is the build.gradle file that calls the room compiler

plugins {
    alias(libs.plugins.androidlibrary)
    alias(libs.plugins.android)
    alias(libs.plugins.compose)
    alias(libs.plugins.ksp)
}

android {
    namespace = "com.grooveshare.database"
    compileSdk = libs.versions.compileSdk.get().toInt()

    defaultConfig {
        minSdk = libs.versions.minSdk.get().toInt()

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles("consumer-rules.pro")
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_21
        targetCompatibility = JavaVersion.VERSION_21
    }
}

dependencies {

    implementation(libs.bundles.default)

    implementation(libs.bundles.navigation)
    ksp(libs.destinationsKsp)
    implementation(libs.bundles.compose)
    implementation(platform(libs.composebom))
    implementation(libs.bundles.lifecycle)
    implementation(libs.bundles.room)
    implementation(libs.bundles.navigation)
    ksp(libs.destinationsKsp)
    implementation(libs.bundles.lifecycle)
}

and here is the versions catalog

[versions]

minSdk = "33"
compileSdk = "36"
permissions = "0.37.3"
agp = "8.12.1"
customtabs = "1.9.0"
coil = "2.7.0"
ktxcore = "1.17.0"
activityCompose = "1.10.1"
activity = "1.10.1"
credentials = "1.5.0"
composeBom = "2025.08.00"
datastore = "1.1.7"
splash = "1.0.1"
espresso = "3.7.0"
googleid = "1.1.1"
hilt = "2.57"
hiltCompiler = "2.57"
junit = "4.13.2"
junitVersion = "1.3.0"
serialization = "1.9.0"
ksp = "2.2.0"
kspPlugin = "2.2.10-2.0.2"
lifecycleRuntime = "2.9.2"
hiltNavigation = "1.2.0"
okhttp = "5.1.0"
retrofit = "3.0.0"
room = "2.7.2"
workmanager = "2.10.3"
kotlin = "2.2.10"
appcompat = "1.7.1"
playServicesLocation = "21.3.0"
material = "1.12.0"


[libraries]

permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "permissions" }
activity = { module = "androidx.activity:activity-ktx", version.ref = "activity" }
activitycompose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
customtabs = { module = "androidx.browser:browser", version.ref = "customtabs" }
core = { module = "androidx.core:core-ktx", version.ref = "ktxcore" }
splash = { module = "androidx.core:core-splashscreen", version.ref = "splash" }
credentials = { module = "androidx.credentials:credentials", version.ref = "credentials" }
credentialsplayservices = { module = "androidx.credentials:credentials-play-services-auth", version.ref = "credentials" }
datastore = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" }
espresso = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso" }
foundation = { module = "androidx.compose.foundation:foundation" }
hiltnavigation = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigation" }
junitext = { module = "androidx.test.ext:junit", version.ref = "junitVersion" }
lifecycleruntime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycleRuntime" }
material = { module = "androidx.compose.material3:material3" }
roomcompiler = { module = "androidx.room:room-compiler", version.ref = "room" }
roomruntime = { module = "androidx.room:room-runtime", version.ref = "room" }
room = { module = "androidx.room:room-ktx", version.ref = "room" }
ui = { module = "androidx.compose.ui:ui" }
uigraphics = { module = "androidx.compose.ui:ui-graphics" }
uitooling = { module = "androidx.compose.ui:ui-tooling" }
uitoolingpreview = { module = "androidx.compose.ui:ui-tooling-preview" }
workmanager = { module = "androidx.work:work-runtime-ktx", version.ref = "workmanager" }
coil = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
destinationsKsp = { module = "io.github.raamcosta.compose-destinations:ksp", version.ref = "ksp" }
googleid = { module = "com.google.android.libraries.identity.googleid:googleid", version.ref = "googleid" }
junit = { module = "junit:junit", version.ref = "junit" }
composebom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" }
serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
hiltcompiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hiltCompiler" }
hilt = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
destinationsCore = { module = "io.github.raamcosta.compose-destinations:core", version.ref = "ksp" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
location = { group = "com.google.android.gms", name = "play-services-location", version.ref = "playServicesLocation" }
google-material = { group = "com.google.android.material", name = "material", version.ref = "material" }


[plugins]

androidapplication = { id = "com.android.application", version.ref = "agp" }
android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
ksp = { id = "com.google.devtools.ksp", version.ref = "kspPlugin" }
androidlibrary = { id = "com.android.library", version.ref = "agp" }


[bundles]

compose = [
    "ui",
    "uitoolingpreview",
    "uitooling",
    "foundation",
    "material",
    "uigraphics"
]

lifecycle = [
    "core",
    "activitycompose",
    "activity",
    "lifecycleruntime"
]

navigation = [
    "hiltnavigation",
    "destinationsCore"
]

di = [
    "hilt",
    "hiltcompiler"
]

networking = [
    "retrofit",
    "converter-gson",
    "okhttp"
]

room = [
    "room",
    "roomruntime",
    "roomcompiler"
]

credentials = [
    "credentials",
    "credentialsplayservices"
]

default = [
    "junit",
    "junitext",
    "espresso",
    "appcompat",
    "core"
]

ive tried forcing the newer version by

configurations.all {
    resolutionStrategy {
        force("org.jetbrains:annotations:23.0.0")
        eachDependency {
            if (requested.group == "com.intellij" && requested.name == "annotations") {
                useVersion("23.0.0")
            }
        }
    }
}

but that didnt work


Solution

  • This is caused by an improper usage of the Room compiler dependency.

    You use it in your gradle file with implementation() (via a version catalog bundle), but it must be used with ksp() instead.

    To fix it, remove the dependency from the bundle like this:

    room = [
        "room",
        "roomruntime",
    ]
    

    And add this to your app-level gradle file:

    ksp(libs.roomcompiler)
    

    That's it.


    By the way, the same applies to hiltcompiler. It doesn't mess with your build right now because you didn't use the di bundle you defined in the version catalog, but you still might want to fix it.

    And you also might want to remove the duplicate entries for the following, they are only needed once in your grade file:

    implementation(libs.bundles.navigation)
    ksp(libs.destinationsKsp)
    implementation(libs.bundles.lifecycle)