16

Android.com says to add these dependencies to your gradle file. I keep getting an error on the lines that start with kapt and ksp saying could not find those methods. Any ideas? Sorry I am not smart.

//below is what android says to put in

def room_version = "2.3.0"

implementation("androidx.room:room-runtime:$room_version")
annotationProcessor "androidx.room:room-compiler:$room_version"

// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room_version")
// To use Kotlin Symbolic Processing (KSP)
ksp("androidx.room:room-compiler:$room_version")

// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$room_version")

// optional - RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"

// optional - RxJava3 support for Room
implementation "androidx.room:room-rxjava3:$room_version"

// optional - Guava support for Room, including Optional and 
ListenableFuture
implementation "androidx.room:room-guava:$room_version"

// optional - Test helpers
testImplementation("androidx.room:room-testing:$room_version")

// optional - Paging 3 Integration
implementation("androidx.room:room-paging:2.4.0-alpha04")

Build file 'C:\Users\tanne\AndroidStudioProjects\LazyAlarm\app\build.gradle' line: 51

A problem occurred evaluating project ':app'.

Could not find method kapt() for arguments [androidx.room:room-compiler:2.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

////////////////////////////////////////// //gradle file below

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

android {
compileSdk 31

defaultConfig {
    applicationId "com.example.lazyalarm"
    minSdk 22
    targetSdk 31
    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'
}
}

 dependencies {

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.room:room-ktx:2.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def room_version = "2.3.0"

implementation("androidx.room:room-runtime:$room_version")
annotationProcessor "androidx.room:room-compiler:$room_version"

// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room_version")
// To use Kotlin Symbolic Processing (KSP)
ksp("androidx.room:room-compiler:$room_version")

// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$room_version")

// optional - RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"

// optional - RxJava3 support for Room
implementation "androidx.room:room-rxjava3:$room_version"

// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"

// optional - Test helpers
testImplementation("androidx.room:room-testing:$room_version")

// optional - Paging 3 Integration
implementation("androidx.room:room-paging:2.4.0-alpha04")

}
2
  • Most likely, you are missing 1-2 plugins. You might want to edit your question and post the entire Gradle file (just one copy, not two), and remove the stack trace from the error report (as that is not informative, but makes your question appear very long). Commented Aug 6, 2021 at 23:34
  • I apologize for the mess. I have cleaned it up and posted the entire gradle file. Please let me know if I am missing a plugin. I do get a depreciated warning for kotlin-android-extensions, if you know what to use to replace this that would be great, as it auto connects my xml items. Commented Aug 7, 2021 at 2:16

6 Answers 6

28

You appear to have copied a bunch of lines into your build.gradle file verbatim from Google's documentation. Unfortunately, their documentation has issues. In particular, many of those lines represent choices, and you need to choose which ones you need. In particular, pick exactly one of these two lines:

kapt("androidx.room:room-compiler:$room_version")
ksp("androidx.room:room-compiler:$room_version")

...and pick one of these four lines:

implementation("androidx.room:room-ktx:$room_version")
implementation "androidx.room:room-rxjava2:$room_version"
implementation "androidx.room:room-rxjava3:$room_version"
implementation "androidx.room:room-guava:$room_version"

Then, depending on your choice from that first pair, you may need to add another plugin to your plugins block at the top of the file. If you choose the kapt line, you need to add id 'kotlin-kapt'. I have not used the ksp option and do not know what plugin you need for it, if any.

Sign up to request clarification or add additional context in comments.

3 Comments

It was the plugin I needed and the removal of the ksp. Thank you for your answer, I am sorry I seem lacking in my knowledge. For some reason I read it off androids website that I was to place all of that in my code, and the optional stuff would just be extra fluff and not crash the program. I was also reading from a different site that had outdated information, so it is a bit confusing.
@auotive: I agree that Google's documentation sometimes can be confusing in how they present things like Gradle dependencies. I am glad that you got it working!
As of today, Google's official docs are still misleading everyone.
6

use ksp

The following works for me.

  • settings.gradle

     pluginManagement {
     repositories {
         gradlePluginPortal()
         google()
     }
     plugins {
         id("com.google.devtools.ksp") version "1.6.20-1.0.5"
     }
    

ksp version reference: Maven Repository: com.google.devtools.ksp

  • app/build.gradle

    plugins {
      id 'com.google.devtools.ksp'    }
    
    implementation("androidx.room:room-runtime:$rootProject.roomVersion")
    annotationProcessor("androidx.room:room-compiler:$rootProject.roomVersion")
    ksp("androidx.room:room-compiler:$rootProject.roomVersion")
    
  • build.gradle

     buildscript {  
    
     ext {
      // app dependencies
      kotlinVersion = '1.6.20'
      roomVersion = '2.4.2' }
     }
    

1 Comment

Tried this but it didn't work out for me, in fact I got an error that This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.6.20
2

try this dependency

def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
testImplementation "android.arch.persistence.room:testing:$room_version"

Comments

1

Solved this by adding androidx.room.room-paging library in the gradle file(app)

// room-paging artifact
    implementation 'androidx.room:room-paging:2.4.3'

You can find the latest dependency from the Google's Maven Repository.

In addition, I had these other dependencies for ROOM and Paging 3.

// Room
    implementation "androidx.room:room-runtime:2.4.3"
    kapt "androidx.room:room-compiler:2.4.3"

    // Paging 3.0
    implementation 'androidx.paging:paging-compose:1.0.0-alpha16'

Comments

1

FOR NEW VIRSION ANDROID:

you can use this way too, for new virsion of android studio whit libs:

step 1 : go to libs.version.toml =>

add in version part this (room = "2.6.1")

step 2 : add to libraries =>

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

tip: you should after every add code touch sync

step 3: go to build.gradle.ktx and add this in the dependencies =>

implementation(libs.room)
implementation(libs.room.runtime)
annotationProcessor(libs.room.compiler)

if you going to use KSP you must add this too :

step 1: go to https://github.com/google/Ksp

step 2 : check the releases , for example for now: 1.9.21-1.0.15

step3 : go to libs.version.toml =>

add in version part this (ksp = "1.9.21-1.0.15")

step 4: at the page go to pluguns ad this:

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

tip: you should after every add code touch sync

step 5: go to build.gradle.ktx(project) in the plugins and add this =>

alias(libs.plugins.ksp) apply false

sync

step 6 : go to build.gradle.ktx (Moudule) and add this in plugin =>

alias(libs.plugins.ksp)

sync

step 7 : go to build.gradle.ktx (Moudule) and add this in dependencies =>

ksp(libs.room.compiler)

libs.version

dependencies

plugins in module

plugin in Project

Comments

0

i faced the same problem and came here to solve nothing worked for me ((with kotlin not java)) until i added the pluging :

id 'kotlin-kapt'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.