Problems with suspend in CrimeDao

Hi,

I have problems when following chapter 13 in the book. I’ve finished everything until page 283 where it says to run the app at the end of the page. I have tried running the solutions that come with the book for chapter 13 as well and get the same errors. There seems to be some problem with using suspend functions on classes with the Dao annotation. The function getCrimes() that is using Flow does work but the function to get a specific crime does not and I end up with the errors in the screenshot below. I have also added my gradle file’s content at the bottom.

This is my gradle file:

plugins {
id ‘com.android.application’
id ‘org.jetbrains.kotlin.android’
id ‘org.jetbrains.kotlin.kapt’
id ‘androidx.navigation.safeargs’
}

android {
namespace ‘sime3134.github.io.criminalintent’
compileSdk 33

defaultConfig {
    applicationId "sime3134.github.io.criminalintent"
    minSdk 24
    targetSdk 33
    versionCode 1
    versionName "1.0"

    javaCompileOptions {
        annotationProcessorOptions {
            arguments += [
                    "room.schemaLocation": "$projectDir/schemas".toString()
            ]
        }
    }

    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'
}

buildFeatures {
    viewBinding true
}

}

dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.fragment:fragment-ktx:1.6.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.room:room-runtime:2.5.2'
implementation 'androidx.room:room-ktx:2.5.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
kapt 'androidx.room:room-compiler:2.5.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

}

If you look at this forum, you can see a lot of other people running into similar issues. You are definitely not alone with this issue.

Could you try sharing the code for Crime and CrimeDao? Also, could you try this fix and see if it makes things better for you (app:kaptDebugKotlin execution failed - #4 by iEbs11)?

Sorry for missing the other threads about this on the forum.

I have just now finally managed to solve the issue on my end. I had apparently managed to update Kotlin to 1.9.0 in the project gradle file. I guess that the required plugins do not support Kotlin 1.9.0. For me the solution was simply to downgrade to Kotlin 1.8.20.

id 'org.jetbrains.kotlin.android' version '1.8.20' apply false

I hope this will help someone else with the same problem.

1 Like