【发布时间】:2019-12-11 00:40:12
【问题描述】:
我使用 Android Studio 4.0 Canary 6 创建了一个全新的 jetpack compose 项目(来自项目模板),并尝试添加房间依赖项。
这是我的应用级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 一起使用?
【问题讨论】:
-
AFAIK,目前无法使用。 Compose 所依赖的一些特殊 Kotlin 魔法与 Room 等注释处理器之间存在冲突。
-
完全正确——我用
kapt "androidx.databinding"尝试了compose = true并得到了同样的错误。可能只是compose与kapt不兼容。 -
感谢@OvermindJiang,您节省了一天。
标签: android android-studio android-room android-jetpack-compose