Jetpack编写中断Room编译器


11

我使用Android Studio 4.0 Canary 6创建了一个全新的jetpack撰写项目(通过项目模板),并尝试添加房间相关性。这是我的应用程序级别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'
}

当我尝试构建它时,出现此错误:

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 true

有谁知道如何解决此问题,或者会议室数据库目前无法与Compose一起使用?


1
AFAIK,目前暂时无法使用。Compose所依赖的某些特殊Kotlin魔术与某些注解处理器(例如Room)之间存在冲突。
CommonsWare

确实-我尝试compose = truekapt "androidx.databinding"并遇到相同的错误。可能仅仅是compose与kapt不兼容。
压倒姜

Answers:


6

应该在1.3.61中修复...但是Jetpack Compose编译器插件未更新。

您可以在以下YouTrack问题中找到更多信息:IR(Jetpack编写),KAPT,会议室:“ AssertionError:IR后端不应调用KotlinTypeMapper.mapType:MainActivity”。最后评论指出:

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

另外,Google Issue Tracker中的以下问题:启用撰写功能时,注释处理器失败

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.