尝试使用android创建房间数据库,但不断收到依赖错误 [英] Trying to create room database with android, but keep getting dependency error

查看:26
本文介绍了尝试使用android创建房间数据库,但不断收到依赖错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android.com 说要将这些依赖项添加到您的 gradle 文件中.我一直在以 kapt 和 ksp 开头的行上收到错误,说找不到这些方法.有任何想法吗?对不起,我不聪明.

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.

//下面是android说要放入的内容

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

构建文件'C:\Users\tanne\AndroidStudioProjects\LazyAlarm\app\build.gradle' 行:51

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

评估项目:app"时出现问题.

A problem occurred evaluating project ':app'.

在 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的对象上找不到参数 [androidx.room:room-compiler:2.3.0] 的方法 kapt().

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文件

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

}

推荐答案

您似乎已经从 Google 的文档中逐字复制了一堆行到您的 build.gradle 文件中.不幸的是,他们的文档有问题.特别是,其中许多行代表选择,您需要选择您需要的那些.特别是,请选择以下两行之一:

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"

然后,根据您从第一对中的选择,您可能需要在文件顶部的 plugins 块中添加另一个插件.如果选择 kapt 行,则需要添加 id 'kotlin-kapt'.我没有使用 ksp 选项,不知道你需要什么插件,如果有的话.

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.

这篇关于尝试使用android创建房间数据库,但不断收到依赖错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆