当androidx.room我想使用Kotlin扩展和协同程序支持Room时,我需要添加实现(“www.example.com:room-ktx:2.5.1”)吗?

yvt65v4c  于 2023-04-28  发布在  Android
关注(0)|答案(2)|浏览(197)

bounty将在6天后到期。回答此问题可获得+50声望奖励。HelloCW正在寻找来自信誉良好的来源的答案

代码A来自https://developer.android.com/training/data-storage/room#groovy
代码B来自https://developer.android.com/training/data-storage/room#kts
如果我需要使用Kotlin扩展和协程支持Groovy设置的Room,我需要在代码A中添加implementation("androidx.room:room-ktx:$room_version")吗?

代码A

dependencies {
    def room_version = "2.5.1"

    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"

    ...
}

代码B

dependencies {
    val room_version = "2.5.1"

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

   ...
}
gtlvzcf8

gtlvzcf81#

是的,如果你想在Room中使用Kotlin扩展和协程支持,你需要在Gradle文件中添加以下实现依赖:

implementation "androidx.room:room-ktx:$room_version"
lb3vh1jj

lb3vh1jj2#

是的,您应该将implementation(“androidx.room:room-ktx:$room_version”)添加到Room中,将其与Kotlin协程一起使用

相关问题