如何在android studio中添加房间依赖?

问题描述 投票:0回答:1

我正在尝试添加这些依赖项,但使用 libs 对象添加其他依赖项,我观看了多个 YouTube 视频,但没有一个视频使用 libs obj,它们只是添加依赖项而没有问题。 这是我要添加的依赖项:

 // Navigation Component
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'

    // Room components
    implementation "androidx.room:room-runtime:2.2.5"
    kapt "androidx.room:room-compiler:2.2.5"
    implementation "androidx.room:room-ktx:2.2.5"
    androidTestImplementation "androidx.room:room-testing:2.2.5"

    // Lifecycle components
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"

    // Kotlin components
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5"

我尝试将其与其他类似的方法一起添加,但没有成功:

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.ui)
  ....
    implementation(kotlin("script-runtime"))
    //added 
    // Navigation Component
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'

    // Room components
    implementation "androidx.room:room-runtime:2.2.5"
    kapt "androidx.room:room-compiler:2.2.5"
    implementation "androidx.room:room-ktx:2.2.5"
    androidTestImplementation "androidx.room:room-testing:2.2.5"

}
android dependencies
1个回答
0
投票

最新的 room 版本使用 ksp 而不是 kapt。这是使用 ksp 添加房间的步骤

将其放在

setting.gradle
的顶部替换您项目后面的kotlin版本

pluginManagement {
    plugins {
        id 'com.google.devtools.ksp' version '1.9.20-1.0.14' apply false
    }
}

更新模块(应用程序模块或库模块)的

build.gradle

plugins {
    id 'com.google.devtools.ksp'
}

android {
    ksp {
        arg('room.schemaLocation', "$projectDir/schemas")
    }
}

dependencies {
    def room_version = "2.6.1"

    implementation "androidx.room:room-ktx:$room_version"
    ksp "androidx.room:room-compiler:$room_version"
}

请注意,这是常规配置

© www.soinside.com 2019 - 2024. All rights reserved.