首页 > 解决方案 > java.lang.IllegalStateException:后端内部错误:代码生成期间出现异常

问题描述

我正在尝试新的 Jetpack compose,但是当我切换到 时kapt,我收到此错误:java.lang.IllegalStateException: Backend Internal error: Exception during code generation.

它与 annotationProcessor 一起工作得很好,但我想在这个项目中使用 kapt。我将不胜感激。

我知道很多问题都可能导致上述错误,但我认为这个问题是特有的,jetpack并且kapt

我在.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 "me.jerryhanks.pinchme"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

//        javaCompileOptions {
//            annotationProcessorOptions {
//                arguments = [
//                        "room.schemaLocation":"$projectDir/schemas".toString(),
//                        "room.incremental":"true",
//                        "room.expandProjection":"true"]
//            }
//        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    buildFeatures {
        compose true
    }

// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)


    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

}

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'

    /**Compose*/
    implementation 'androidx.ui:ui-layout:0.1.0-dev02'
    implementation 'androidx.ui:ui-material:0.1.0-dev02'
    implementation 'androidx.ui:ui-tooling:0.1.0-dev02'

    /**Corountine*/
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.coroutine"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.coroutine"
//    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$versions.coroutine"

    /**Room*/
    implementation "androidx.room:room-runtime:$versions.room"
    kapt "androidx.room:room-compiler:$versions.room"

    /**Test*/
    testImplementation 'junit:junit:4.12'
    testImplementation "androidx.room:room-testing:$versions.room"

    /**Android Test*/
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

标签: androidkotlinillegalstateexceptionandroid-jetpackandroid-jetpack-compose

解决方案


这似乎是团队仍在努力解决的错误。

Compose 仍处于试验阶段,不应在生产应用程序中使用。此外,Compose 需要为 Kotlin 编译器启用新的/实验性的 IR(中间表示)后端,因此您可能会遇到与新后端相关的语言错误。

Compose 确实需要 IR 后端(带有 Google 扩展)。


推荐阅读