以下选项未被任何处理器识别:'[kapt.kotlin.generated, room.incremental]'

The following options were not recognized by any processor: '[kapt.kotlin.generated, room.incremental]'

:app:kaptDebugKotlin
w: warning: The following options were not recognized by any processor: '[kapt.kotlin.generated, room.incremental]'

为什么我会收到这个?我在多模块项目中使用 Room。

共享库模块: api "androidx.room:room-runtime:$room_version" api "androidx.room:room-ktx:$room_version" api "androidx.room:room-rxjava2:$room_version"

应用程序模块:

kapt "androidx.room:room-compiler:$room_version"

Gradle.properties

kapt.incremental.apt=true

Build.gradle 默认配置包括 these compile options:

javaCompileOptions {
        annotationProcessorOptions {
            arguments = ["room.incremental":"true"]
        }
    }

已添加到房间的多模块项目可能会出现此类问题。对于这样的项目,问题是由于将派生的 RoomDatabase class 添加到库模块,但配置了应用程序模块的 build.gradle。

解决方案是配置包含派生的 RoomDatabase 的模块的 build.gradle class。

  • 在 build.gradle 文件的 dependencies{} 部分添加房间编译器的依赖。
kapt "android.arch.persistence.room:compiler:$room_version"

请注意,对于基于 java 的项目,请使用以下代码

annotationProcessor "android.arch.persistence.room:compiler:$room_version"

虽然我同意模块中缺少 kapt 是 IDE 中的原始问题。

  • "androidx.room:room-compiler:${roomVersion}"

在 CLI 中可以有其他的,你可以看到详细的警告:

Current JDK version 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12 has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.warning: The following options were not recognized by any processor: '[kapt.kotlin.generated, room.incremental]'[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).

我以前遇到过这个问题:我做了什么?

首先,在 build.gradle 文件中名为 defaultConfig 的对象中,我必须删除:

javaCompileOptions {
    annotationProcessorOptions {
        arguments = ["room.incremental":"true"]
    }
}

我必须更换:

implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"

有:

// Room components
def room_version = "2.2.5"
implementation "android.arch.persistence.room:runtime:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
kaptAndroidTest "android.arch.persistence.room:testing:$room_version"

// Lifecycle components
def archLifecycleVersion = "2.2.5"
implementation "android.arch.lifecycle:extensions:$archLifecycleVersion"
kapt "android.arch.lifecycle:compiler:$archLifecycleVersion"

其次,在gradle.properties中我添加:

kapt.incremental.apt=true
kapt.use.worker.api=true
android.lifecycleProcessor.incremental=true

有关此配置,请参阅