0

have tried to implement coroutines/room in two projects and I get the same error. Please help me!!!

Execution failed for task ':app:kaptDebugKotlin'

error: type of the parameter must be a class annotated with @Entity or a collection/array of it.
    kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

This is my room database class:

@Database(entities = [Meal::class], version = 1, exportSchema = false)
@TypeConverters(MealTypeConvertor::class)
abstract class MealDataBase : RoomDatabase() {
    abstract fun mealDao(): MealDao

    companion object {
        @Volatile
        var INSTANCE: MealDataBase? = null

        @Synchronized
        fun getInstance(context: Context): MealDataBase {
            if (INSTANCE == null) {
                INSTANCE = Room.databaseBuilder(
                    context,
                    MealDataBase::class.java,
                    "meal.db"
                ).fallbackToDestructiveMigration()
                    .build()
            }
            return INSTANCE as MealDataBase
        }

    }
}

This my model data Class with the @Entity anotation:

@Entity(tableName = "mealInformation")
data class Meal(
val dateModified: Any?,
@PrimaryKey
val idMeal: String,
val strArea: String?,
val strCategory: String?,
val strCreativeCommonsConfirmed: Any?,
val strDrinkAlternate: Any?,
val strImageSource: Any?,
val strIngredient1: String?
)

My class is already noted with @Entity and my version of gradle is up to date. My dependencies:

dependencies {
def nav_version = "2.3.5"
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
apply plugin: 'kotlin-kapt'

//Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

//intuit
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'

//gif
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.17'

//Retrofit
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

//images
implementation 'com.github.bumptech.glide:glide:4.13.2'

//videoModel mvvm
def lifecycle_version = "2.4.0-rc01"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"

//room
def roomVersion = "2.4.2"
implementation("androidx.room:room-runtime:$roomVersion")
annotationProcessor("androidx.room:room-compiler:$roomVersion")
kapt("androidx.room:room-compiler:$roomVersion")
implementation("androidx.room:room-ktx:$roomVersion")

}

My class is already noted with @Entity and my version of gradle is up to date

4
  • 3
    Please provide enough code so others can better understand or reproduce the problem. Commented Aug 2, 2022 at 7:03
  • Can you provide the piece of code that causes this error? Commented Aug 2, 2022 at 8:07
  • I vaguely recall a question along similar lines where the issue, if I recall correctly, was the mix of Java and Kotlin and the annotationProcessor/kapt both being coded. Commented Aug 2, 2022 at 10:33
  • @MikeT Thanks to you I oriented my search to solve the problem correctly. Commented Aug 3, 2022 at 6:39

2 Answers 2

1

The previous solution was only useful for a short time, the real problem was that I had to update gradle. In the classpath I added this:

> buildscript {
    repositories {
        ...
        ...
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
        classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:1.7.20-Beta-1.0.6"
        ...
    }

 

    }

Be sure that the ksp version match with your kotlin plugin version, you can also check the maven website here: Maven

Then in the build.gradle add the ksp plugin, add the new ksp compileOption and change the kap annotatons to ksp:

    plugins {
    ...
    ...
    id 'com.google.devtools.ksp'
    }
    android{
    ...
    ksp {
        arg("room.schemaLocation", "$projectDir/schemas".toString())
    }
    ...
    
}
dependencies {
    ...
    //room
    def roomVersion = "2.4.3"

    implementation("androidx.room:room-runtime:$roomVersion")
    ksp "androidx.room:room-compiler:$roomVersion"
    implementation("androidx.room:room-ktx:$roomVersion")
    ...

}

Sign up to request clarification or add additional context in comments.

Comments

0

[READ THE NEW ANSWER] After trying a lot of things I finally found the error, which was very stupid. The problem was that I repeated twice the implementation of the room-compiler dependency.

I deleted the kapt dependency. Anyway this link helped me to identify the problem Error:Execution failed for task ':app:kaptDebugKotlin'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.