Jetpack compose 破坏了 Room 编译器 [英] Jetpack compose breaks Room compiler

查看:61
本文介绍了Jetpack compose 破坏了 Room 编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Android Studio 4.0 Canary 6 创建了一个全新的 jetpack compose 项目(来自项目模板),并尝试添加房间依赖项.这是我的应用级 build.gradle:

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;

这可以通过删除 kapt "androidx.room:room-compiler:2.2.2" 或禁用 compose compose true

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

有没有人知道如何解决这个问题,或者房间数据库目前无法与 Compose 一起使用?

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

推荐答案

应该在 1.3.61 中修复...但 Jetpack Compose 编译器插件没有更新.

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

您可以在以下 YouTrack 问题中找到更多信息:IR (Jetpack Compose)、KAPT、Room:断言错误:IR 后端不应调用 KotlinTypeMapper.mapType:MainActivity".最后一条评论指出:

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:

这里的问题是 JetPack Compose 尚未将其内部 Kotlin 编译器更新到 1.3.61.我们会看看我们能做些什么.

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.

此外,Google 问题跟踪器中存在以下问题:启用撰写时注释处理器失败

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

这篇关于Jetpack compose 破坏了 Room 编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆