android – How to get rid of Incremental annotation processing requested warning?-ThrowExceptions

Exception or error:

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'
}
How to solve:

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.

###

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?

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

Edit:

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.

###

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.

###

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 

###

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

###

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.

###

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

###

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.

###

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

###

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.

Leave a Reply

Your email address will not be published. Required fields are marked *