Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of Incremental annotation processing requested warning?

People also ask

What is incremental annotation processing?

Last modified: 29 July 2022. Incremental processing is a processing technique that avoids re-processing of sources as much as possible.

What is an annotation processor?

Annotation processing is a powerful tool for generating code for Android apps. In this tutorial, you'll create one that generates RecyclerView adapters.

What is kapt in Kotlin?

1. Kapt is the Kotlin Annotation Processing Tool, and it's in pretty good shape these days. If you want to be able to reference generated code from Kotlin, you need to use kapt. To do that, simply include the plugin in your build.gradle file with the line : apply plugin: 'kotlin-kapt' 2.


Just add this line to you gradle.properties:

kapt.incremental.apt=true

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"
        }
    }

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.


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.


Enable Kapt Incremental annotation processing requeste

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

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