6
votes

I am trying to set up Android Room in my Jetpack Compose project. However, when trying to add...

kapt "androidx.room:room-compiler:2.2.3"

... to the app build.gradle dependencies. My build fails with the error...

e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;

Any insight as to why this is? Can we use Android Room with Jetpack Compose yet?

3
If I remember correctly, this was a bug on the kotlin compiler which is now fixed. Not sure if they pulled the changes to the Jetpack plugin yet. Do you use the latest version?Giorgos Neokleous
Hi, yea I believe I'm using the latest versions. ext.kotlin_version = "1.3.61" ext.compose_version = '0.1.0-dev03'Michael Johnston
It has not been fixed as of todayalizx

3 Answers

3
votes

I'm pretty sure that we're still in a state where annotation processors (for Room, Retrofit, etc.) and the experimental Kotlin compiler are not getting along. The recommended approach at the moment is to isolate the Compose stuff in a module that is independent of modules that need annotation processors.

3
votes

This is currently not supported as kapt does not play well with Jetpack Compose. This issue is being tracked here - https://issuetracker.google.com/issues/143232368

0
votes

It's actually working, but not without some changes.

For a new project created with AndroidStudio 2020.3.1 Canary 2:

In build.gradle (Project): Downgrade compose_version to 1.0.0-alpha07 and ext.kotlin_version to 1.4.10.

In build.gradle (Module):

Under composeOptions downgrade the composeCompilerVersion to 1.4.10.

Under dependencies change "androidx.compose.ui:ui-tooling:$compose_version" to "androidx.ui:ui-tooling:$compose_version".

In Main activity - change the import for the preview, as it depends on ui-tooling.

Add room dependencies.

Should work.

However, some newer Compose functionalities won't probably work, as they are explicitly stating, that one should use Kotlin version 1.4.20 and above.