0

I want to use the room library for database, when I add the room library to my project, I can easily use it and I have no problem, but in order to be able to use room properly, I must I use ksp, well, when I add the ksp library to my project, Gradle syncs correctly, but when I build my project, I get an error, in the following I will provide you with all the information.

--------------------------------------------------------------------------------------------------------------------------

Error text:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

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

Could not resolve all files for configuration ':app:_agp_internal_javaPreCompileDebug_kspClasspath'. Could not find annotation-1.3.0.jar (androidx.annotation:annotation:1.3.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/annotation/annotation/1.3.0/annotation-1.3.0.jar

  • 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. Get more help at https://help.gradle.org.

2: Task failed with an exception.

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

Could not resolve all files for configuration ':app:kspDebugKotlinProcessorClasspath'. Could not find annotation-1.3.0.jar (androidx.annotation:annotation:1.3.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/annotation/annotation/1.3.0/annotation-1.3.0.jar

  • 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. Get more help at https://help.gradle.org.

--------------------------------------------------------------------------------------------------------------------------

The version of Android Studio that I use: Android Studio Koala | 2024.1.1

--------------------------------------------------------------------------------------------------------------------------

libs.version.toml

[versions]
agp = "8.5.0"
kotlin = "2.0.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"
activity = "1.9.0"
constraintlayout = "2.1.4"

ksp = "2.0.0-1.0.21"
room = "2.6.1"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }

room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

jetbrains-kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

--------------------------------------------------------------------------------------------------------------------------

build.gradle.kts (My Application)

plugins {
    
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.jetbrains.kotlin.android) apply false

    alias(libs.plugins.jetbrains.kotlin.ksp) apply false
    
}

--------------------------------------------------------------------------------------------------------------------------

build.gradle.kts (:app)

plugins {
    
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)

    alias(libs.plugins.jetbrains.kotlin.ksp)

}

android {
    namespace = "com.example.myapplication"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.myapplication"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = 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"
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.activity)
    implementation(libs.androidx.constraintlayout)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)

    implementation(libs.room.runtime)
    implementation(libs.room.ktx)
    ksp(libs.room.compiler)

}

--------------------------------------------------------------------------------------------------------------------------

This is all information about my project, so if someone can solve my problem, I would be really grateful!

1 Answer 1

0

Have you tried to add compose compiler to your gradle files? You need it after kotlin v2.0.0+ :: https://developer.android.com/develop/ui/compose/compiler

Not the answer you're looking for? Browse other questions tagged or ask your own question.