Reputation: 4307
I have just started using android development and trying to use Room library. Since yesterday I am facing this warning message
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.lifecycle.LifecycleProcessor (NON_INCREMENTAL), androidx.room.RoomProcessor (NON_INCREMENTAL).
I have tried to research and fix but unable to avoid this error here is my grale.build file. please suggest/advice what I am doing wrong.
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 "ps.room.bookkeeper"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":"$projectDir/schemas".toString()]
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// life cycle dependencies
def lifecycle_version = "2.0.0"
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
kapt "android.arch.lifecycle:compiler:$lifecycle_version"
//Room dependencies
//def room_version = "2.1.0"
implementation 'android.arch.persistence.room:runtime:2.1.0'
kapt 'android.arch.persistence.room:compiler:2.1.0'
//annotationProcessor 'android.arch.persistence.room:compiler:2.1.0'
// implementation "android.arch.lifecycle:extensions:$room_version"
// kapt "android.arch.persistence.room:compiler:$room_version"
// androidTestImplementation "android.arch.persistence.room:testing:$room_version"
//implementation 'androidx.room:room-runtime:2.1.0'
//annotationProcessor 'androidx.room:room-compiler:2.1.0'
}
Upvotes: 202
Views: 127390
Reputation: 23
for me this is happen when my entity with primay key and @NonNull annotation, but type field still using nullable (?). so, just remove this ?, the problem is gone
data class TvEntity(
@PrimaryKey
@NonNull
@ColumnInfo(name = "tvId")
var tvId: String?,
Upvotes: 0
Reputation: 2802
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"
}
}
Upvotes: 160
Reputation: 91
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.
Upvotes: 1
Reputation: 323
Above answers can be useful, but what helped me is reducing the kotlin_version
in build.gradle(Project)
to 1.3.41
and building the project. This will allow you to see if there is any issue with your entity model.
Mine was, I forgot to annotate @PrimaryKey
. Your may be something different. Kotlin 1.3.41
allows to to see those issues. Fix those issues and revert back your kotlin_version
to the previous one.
Upvotes: 1
Reputation: 2954
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
Upvotes: 32
Reputation: 2799
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.
Upvotes: 0
Reputation: 565
Here is a list of things you can do to fix this and significantly decrease your build times while you're at it.
In your build.gradle
(module) file:
android {
...
defaultConfig {
...
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
arg("room.incremental", "true")
arg("room.expandProjection", "true")
}
}
}
...
}
In your gradle.properties
file:
kapt.incremental.apt=true // enabled by default on 1.3.50+
kapt.use.worker.api=true // faster builds
kapt.include.compile.classpath=false // near instant builds when there are few changes
android.databinding.incremental=true
android.lifecycleProcessor.incremental=true
//add your specific library if it supports incremental kapt
Upvotes: 30
Reputation: 8371
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"]
}
}
Upvotes: 2
Reputation: 3623
A lot of the other answers here cover up the error or disable incremental processing instead of actually making it work the way you want.
You can enable incremental processing for your specific library in the gradle.properties
file. Just add these settings, or whichever one matches the library that throws the error:
android.databinding.incremental=true
android.lifecycleProcessor.incremental=true
Upvotes: 10
Reputation: 997
I'm using AndroidX, but It guess it's the same for android.arch.lifecycle
. For me it simply helped replacing this:
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
... with this:
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
So if you're using android.arch.lifecycle
it might have the same effect replacing this:
kapt "android.arch.lifecycle:compiler:$lifecycle_version"
... with this:
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
Be aware that this only works if you're using Java 8 and that you also should remove OnLifecycleEvent
annotations for LifecycleObserver
classes and let those observers implement DefaultLifecycleObserver
instead.
Changing to this method is also recommended in the build.gradle
depencies shown here.
Upvotes: 1
Reputation: 2437
From Room documentation:
"Room has the following annotation processor options...room.incremental: Enables Gradle incremental annotation proccesor."
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true",
"room.expandProjection":"true"]
}
}
}
}
Be sure to update the room version to 2.2.x or higher.
Upvotes: 41
Reputation: 2455
Just add this line to you gradle.properties:
kapt.incremental.apt=true
Upvotes: 215
Reputation: 439
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.
Upvotes: 9
Reputation: 1678
There is a bug in kotlin-gradle-plugin version of 1.3.50 as @Necrontyr mentioned. Just downgrade the kotlin_version in build.gradle(Project) to 1.3.41.
Upvotes: 80