I just started learning about Android in Kotlin and I was creating a note application just for learning purposes. I wanted to use Room to store saved notes in my database, so i was checking out the developer.android tutorials and We have some necessary dependencies which we have to add in our build.gradle(Module) as mentioned on developer.android.com https://developer.android.com/training/data-storage/room#kts but when i add these dependencies i am having an error which i'm not able to figure out
Could not find method ksp() for arguments [androidx.room:room-compiler:2.4.3] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
I was having the similar error with kapt, but i solved it by adding the necessary plugin in my build.gradle(Module).For now i am removing this implementation from my build.gradle and moving ahead with the test project, but any help would be appreciated, thankyou.
dependencies mentioned in the developer.android.com
dependencies {
val room_version = "2.4.3"
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 Symbol 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:$room_version")
}
my build.gradle(Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
namespace 'android.example.mynotes'
compileSdk 32
defaultConfig {
applicationId "android.example.mynotes"
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'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
def room_version = "2.4.3"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
implementation "androidx.room:room-rxjava3:$room_version"
implementation "androidx.room:room-guava:$room_version"
testImplementation "androidx.room:room-testing:$room_version"
implementation("com.google.devtools.ksp:symbol-processing-api:1.8.0-1.0.8")
kapt "androidx.room:room-compiler:$room_version"
ksp("androidx.room:room-compiler:$room_version")
}
my build.gradle(Project)
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
CodePudding user response:
Make sure you're kotlin gradle plugin version is 1.8.0:
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'
In the app level gradle file add devependency
id 'com.google.devtools.ksp' version '1.8.0-1.0.8'
Finally, build your project.