Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack compose breaks Room compiler

I created a completely fresh jetpack compose project (from the project template) with Android Studio 4.0 Canary 6 and I attempted to add room dependencies. Here is my app-level build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'


android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.example.composewithroom"
        minSdkVersion 29
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        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 {
        compose true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.ui:ui-framework:0.1.0-dev03'
    implementation 'androidx.ui:ui-layout:0.1.0-dev03'
    implementation 'androidx.ui:ui-material:0.1.0-dev03'
    implementation 'androidx.ui:ui-tooling:0.1.0-dev03'


    implementation "androidx.room:room-runtime:2.2.2"
    implementation "androidx.room:room-ktx:2.2.2"
    kapt "androidx.room:room-compiler:2.2.2" // e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

I get this error when I try to build it:

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

This can be either "fixed" by removing kapt "androidx.room:room-compiler:2.2.2" or disabling compose compose true

Does anyone have any idea how to fix this or is the room database just unusable with Compose at the moment?

like image 445
Semanticer Avatar asked Dec 11 '19 00:12

Semanticer


1 Answers

Should be fixed in 1.3.61... but Jetpack Compose compiler plugin is not updated.

You can find more information in the following YouTrack issue: IR (Jetpack Compose), KAPT, Room: "AssertionError: IR backend shouldn't call KotlinTypeMapper.mapType: MainActivity". Last comment states that:

The problem here is that JetPack Compose hasn't updated its internal Kotlin compiler to 1.3.61 yet. We'll see what we can do about it.

Also, the following issue in Google Issue Tracker: Annotation processors fail when compose is enabled

like image 147
Xavier Rubio Jansana Avatar answered Oct 16 '22 23:10

Xavier Rubio Jansana