gpt4 book ai didi

android-studio - 找不到参数的方法 ksp()

转载 作者:行者123 更新时间:2023-12-05 09:25:46 28 4
gpt4 key购买 nike

我刚开始学习 Kotlin 中的 Android,我正在创建一个笔记应用程序,只是为了学习目的。我想使用 Room 将保存的笔记存储在我的数据库中,所以我查看了 developer.android 教程并且我们有一些必要的依赖项,我们必须将其添加到我们的 build.gradle(Module) 中,如 developer.android.com 上所述https://developer.android.com/training/data-storage/room#kts但是当我添加这些依赖项时,我遇到了一个我无法弄清楚的错误

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

我在使用 kapt 时遇到了类似的错误,但我通过在我的 build.gradle(Module) 中添加必要的插件解决了这个问题。现在我正在从我的 build.gradle 中删除这个实现并继续进行测试项目,但任何帮助将不胜感激,谢谢。

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")
}


我的build.gradle(模块)

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")

}


我的build.gradle(项目)

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
}

最佳答案

确保你的kotlin gradle插件版本是1.8.0:

classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'

在app级gradle文件中添加devependency

id 'com.google.devtools.ksp' 版本 '1.8.0-1.0.8'

最后,构建您的项目。

关于android-studio - 找不到参数的方法 ksp(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75070898/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com