【Room】エラー虎の巻2 - Ki-Kobayashi/Android-Wiki GitHub Wiki

🛑 Kotlin1.9でRoomを使用すると、Daoでエラーが出る

TaskDao.java:19: �G���[: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
    kotlin.coroutines.Continuation<? super kotlin.Unit> $completion);
                                                        ^
TaskDao.java:17: �G���[: Not sure how to handle insert method's return type.
    public abstract java.lang.Object insertTask(@org.jetbrains.annotations.NotNull
TaskDao.java:27: �G���[: Not sure how to handle delete method's return type. Currently the supported return types are void, int or Int.
    public abstract java.lang.Object deleteTask(@org.jetbrains.annotations.NotNull
TaskDao.java:29: �G���[: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
    kotlin.coroutines.Continuation<? super kotlin.Unit> $completion);
TaskDao.java:35: �G���[: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
    kotlin.coroutines.Continuation<? super kotlin.Unit> $completion);
TaskDao.java:33: �G���[: Not sure how to handle update method's return type. Currently the supported return types are void, int or Int.
    public abstract java.lang.Object updateTask(@org.jetbrains.annotations.NotNull

### 💡原因💡 下記の組み合わせが悪いと出るよう...

  • kotlinのバージョン
  • Roomのバージョン
  • ksp/kapt

🌟参考:https://issuetracker.google.com/issues/236612358

### 💡解決方法💡 ※kotlinのバージョンが1.9の場合(proj/build.gradle > "org.jetbrains.kotlin.android"で確認)の解決方法

  • RoomはKspを使用するようにする
  • kspのバージョン:Kotlinバージョンと合わせる
  • Roomのバージョン:2.6.0~
  • Hiltのバージョン:2.48~(Ksp利用のため上げておく)

🟩 proj / build.gradle

plugins {
    id("com.android.application") version "8.2.0" apply false
  🌟id("org.jetbrains.kotlin.android") version "1.9.0" apply false
  🌟id("com.google.dagger.hilt.android") version "2.48" apply false
  🌟id("com.google.devtools.ksp") version "1.9.0-1.0.12" 
}

🟩 app / build.gradle

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.google.devtools.ksp")
    id("com.google.dagger.hilt.android")
}
android{...}

dependencies {
    implementation("androidx.core:core-ktx:1.10.1")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
    implementation("androidx.activity:activity-compose:1.7.0")
    implementation(platform("androidx.compose:compose-bom:2023.08.00"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")

  🌟val room_version = "2.6.0"
    implementation("androidx.room:room-runtime:$room_version")
    annotationProcessor("androidx.room:room-compiler:$room_version")
  🌟ksp("androidx.room:room-compiler:$room_version")
    implementation("androidx.room:room-ktx:$room_version")

  🌟val hilt_version = "2.48"
    implementation("com.google.dagger:hilt-android:$hilt_version")
  🌟ksp("com.google.dagger:hilt-android-compiler:$hilt_version")
}

🛑 K

### 💡解決方法💡

🛑 K

### 💡解決方法💡

🛑 K

### 💡解決方法💡

🛑 K

### 💡解決方法💡

🛑 K

### 💡解決方法💡