I have just started using android development and trying to use Room library. Since yesterday I am facing this warning message
w: [kapt] Incremental a
If it's complaining that "Incremental annotation processing requested, but support is disabled because the following processors are not incremental", then setting "kapt.incremental.apt" to "true" (mentioned in a different answer) in gradle.properties is counter-intuitive. You need to set it to "false". That did it for me.
Use Kotlin 1.3.31 or newer Kotlin 1.3.30 released
In your android kotlin project gradle.properties file
# Enable Kapt Incremental annotation processing requeste
kapt.incremental.apt=true
# Enable android.databinding.annotationprocessor.ProcessDataBinding (DYNAMIC)
android.databinding.incremental=true
# Decrease gradle builds time
kapt.use.worker.api=true
# turn off AP discovery in compile path, and therefore turn on Compile Avoidance
kapt.include.compile.classpath=false
# Enable In Logcat to determine Kapt
kapt.verbose=true
This can also be caused by character problems such as "İ" on the databinding side when the system language is a non-English language. In such a case, using the computer system language in English will solve the problem.
The real problem is that incremental processing makes things faster, but if any of the annotation processors are non incremental, none of them will be actually processed in that way.
What's the purpose of incremental processing?
From version 1.3.30+, incremental processing allowed modules not to be entirely processed again each time a change occurs, giving the build process a better performance:
The main areas of focus for this release have been around Kotlin/Native, KAPT performance, as well as improvements for IntelliJ IDEA.
From Kotlin documentation:
Annotation processors (see JSR 269) are supported in Kotlin with the kapt compiler plugin. In a nutshell, you can use libraries such as Dagger or Data Binding in your Kotlin projects.
How to fix Room Incremental Processing?
Room incremental annotation processor is disabled by default. This is a known issue and it's described here. They intend to fix it on version 2.2.0. You can just wait for the update or you can enable that to get rid of the warning by setting:
in gradle.properties file:
kapt.incremental.apt=true
(optional steps)
to allow databinding to be incremental:
android.databinding.incremental=true
for faster builds:
kapt.use.worker.api=true
if only a few changes are made, the build time greatly decreases:
kapt.include.compile.classpath=false
(back to the subject)
in your project build.gradle, add the necessary dependencies (Groovy):
dependencies {
...
implementation "androidx.room:room-runtime:2.2.0-rc01"
annotationProcessor "androidx.room:room-compiler:2.2.0-rc01"
}
and
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental":"true"]
}
}
}
}
Kotlin DSL version:
dependencies {
...
implementation("androidx.room:room-runtime:2.2.0-rc01")
kapt("androidx.room:room-compiler:2.2.0-rc01")
}
and
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = mapOf("room.incremental" to "true")
}
}
}
}
October 9, 2019
androidx.room:room-*:2.2.0 is released.
Gradle Incremental Annotation Processor: Room is now a Gradle isolating annotation processor and incrementability can be enabled via the processor option room.incremental.
Latest update:
For the newest Kotlin DSL versions, please use
javaCompileOptions {
annotationProcessorOptions {
arguments["room.incremental"] = "true"
}
}
Starting from version 1.3.30, kapt supports incremental annotation processing as an experimental feature. Yet, starting from version 1.3.50, incremental annotation processing is enabled by default.
So, you must add kapt.incremental.apt=true
line to your gradle.properties
file to enable incremental annotation processing if your kapt version is greater than or equal to 1.3.30 and lower than 1.3.50. Otherwise; you don't have to set kapt.incremental.apt
to true
to enable it. Although, you can set it to false
to disable it if you like.
Besides all of that; incremental annotation processing requires incremental compilation to be enabled as well. So, you must add kotlin.incremental=true
line to your gradle.properties
file to be able to benefit from incremental annotation processing feature.
Note that incremental annotation processing option of Room is ON by default starting from version 2.3.0-alpha02. It means you don't have to set room.incremental
argument to true
if your version of the library is greater than or equal to this. To learn more, see issue #112110217.
Also note that if you're using Android Gradle Plugin 3.6.x or newer, incremental annotation processing option is ON by default for Data Binding. So, you don't have to add android.databinding.incremental=true
line to your gradle.properties
file. To learn more, see issue #110061530.
What you really should do is to implement these lines of code in your buildConfig
tag in your build.gradle
, module app:
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.schemaLocation" : "$projectDir/schemas".toString(),
"room.incremental" : "true",
"room.expandProjection": "true"]
}
}