Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Android Basics: Persist data with Room - Build output error #44

Closed
Andy-Cuong opened this issue Jun 15, 2022 · 2 comments
Closed

Android Basics: Persist data with Room - Build output error #44

Andy-Cuong opened this issue Jun 15, 2022 · 2 comments

Comments

@Andy-Cuong
Copy link

Andy-Cuong commented Jun 15, 2022

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-persisting-data-room

In which task and step of the codelab can this issue be found?
Probably step 6 and in step 9 when running the code

Describe the problem
Build output shows a lot of error when running such as annotation and return type of the functions in DAO, specifically:

  • 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);

  • error: Not sure how to handle insert method's return type.
    public abstract java.lang.Object insert(@org.jetbrains.annotations.NotNull()

  • error: 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 delete(@org.jetbrains.annotations.NotNull()

  • 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);

  • 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);

  • error: 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 update(@org.jetbrains.annotations.NotNull()

Versions
Android Studio version: Chipmunk 2021.2.1
API version of the emulator: API 31

Additional information
image

@shepardsn
Copy link

I ran into the same issue. For me it turned out to be the versions of Room and Kotlin plugin I was using in Android Studio weren't compatible. It looks like you need to use the version of Kotlin that Room has been updated for.

You can look at the release notes for the versions to see roughly which version of Kotlin to use. eg.

For instance in the release notes for 2.4.0-rc01 you can see this comment:
Update Room’s dependency on KSP to 1.6.0-1.0.1 to support Kotlin 1.6

which should be that the stable version of Room (eg. 2.4.2) should work with the Kotlin plugin 1.6.x. (and it does)

https://stackoverflow.com/questions/70241165/room-error-type-of-the-parameter-must-be-a-class-annotated-with-entity-or-a-co

@Andy-Cuong
Copy link
Author

Thank you for clarifying it. I figured it out (partly thanks to @lbrooks2500 in this issue) that I should use the alpha version of Room aka 2.5.0-alpha02 for the kapt "androidx.room:room-compiler" version so that it will be able to build, although other dependencies work fine with the stable version 2.4.2.

My current Kotlin version is 1.7.0, seemingly the latest stable one, so I assume I should stick with it. Seems like it is a matter of compatibility with Room compiler and Kotlin library

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants