【问题标题】:java.lang.IllegalStateException: Backend Internal error: Exception during code generationjava.lang.IllegalStateException:后端内部错误:代码生成期间出现异常
【发布时间】:2020-02-27 12:14:28
【问题描述】:

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

annotationProcessor 可以正常工作,但我想在这个项目中使用 kapt。我将不胜感激。

我知道很多问题都可能导致上述错误,但我认为这是jetpackkapt 所特有的

我在下面添加了我的.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'
}

【问题讨论】:

  • 请发布你的 gradle 文件
  • 我已经添加了我的 .gradle 文件。
  • 我写了这个作为答案,但它被删除了,因为它“没有提供问题的答案”¯\_(ツ)_/¯:由于这个错误,Compose 和 Room 目前不兼容youtrack.jetbrains.com/issue/KT-34583

标签: android kotlin illegalstateexception android-jetpack android-jetpack-compose


【解决方案1】:

这似乎是团队仍在努力的bug

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

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

【讨论】:

    【解决方案2】:

    该问题似乎已在 compose 的较新版本中得到解决。试试 1.0.0beta08

    【讨论】:

      猜你喜欢
      • 2019-02-04
      • 2019-08-16
      • 2022-06-22
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多