I'm new to kotlin Android, today I want to build a database with room based on kotlin. I first to the offical guide of using room with kotlin. As the offical guide says, The dependencies for room are:
def room_version = "2.4.3"
implementation 'com.google.devtools.ksp:symbol-processing-api:1.7.20-1.0.7'
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"
So I add them to my module gradle file and try synchronizing Obviously, the building fails because I didn't enable kapt
So I refered to the officail guide of kapt: as the officail guide of kapt says, I only need to add:
plugins {
id "org.jetbrains.kotlin.kapt" version "1.7.21"
}
to my module gradle file. I did so but the building process failed, it gave the reason:
Error resolving plugin [id: 'org.jetbrains.kotlin.kapt', version: '1.7.21']
> The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
So I searh kapt withgoogle ang I got Could not find method kapt() for arguments Among the answers of the question, I try:
plugins {
...
id 'kotlin-kapt'
}
And it worked. I want to know the reasons.
Appendix:
module gradle file:
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id "org.jetbrains.kotlin.kapt" version "1.7.21"
}
android {
namespace 'me.rexjz.database'
compileSdk 33
defaultConfig {
minSdk 28
targetSdk 33
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 {
def room_version = "2.4.3"
implementation 'com.google.devtools.ksp:symbol-processing-api:1.7.20-1.0.7'
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"
implementation 'androidx.core:core-ktx:1.9.0'
testImplementation 'junit:junit:4.13.2'
// implementation project(":common")
}
project gradle file:
buildscript {
ext {
compose_version = '1.3.1'
compile_version = 33
}
repositories {
google()
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
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.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "CellExperimentAssistant"
include ':app'
include ':authentication'
include ':database'
include ':common'
I want to know Why id "org.jetbrains.kotlin.kapt" fails but id 'kotlin-kapt' works?