197

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'
}
Shax
  • 4,207
  • 10
  • 46
  • 62
  • why is your annotationProcessor commented? Did you try to uncomment them and then build project? (for both room and lifecycle) – Ferhat Ergün Aug 27 '19 at 09:13
  • @FerhatErgün, yes I tried also with annotationProcessor uncommented but even then no luck. – Shax Aug 27 '19 at 09:47
  • 1
    try to add android.enableSeparateAnnotationProcessing=true in your gradle.properities https://www.reddit.com/r/androiddev/comments/ai92pt/whats_the_state_of_incremental_annotation found on this, it might be related to your problem – Ferhat Ergün Aug 27 '19 at 11:05
  • @FerhatErgün, appreciate you are trying to help me out but still no luck – Shax Aug 27 '19 at 11:45
  • 7
    You can downgrade kotlin-gradle-plugin in your project build.gradle file to version 1.3.41 for the time being. I think it is a bug related to kapt. More info: https://youtrack.jetbrains.com/issue/KT-33515 – Necrontyr Aug 27 '19 at 18:02
  • i am having the same problem after updating to 1.3.50 – Lekr0 Aug 27 '19 at 18:36
  • 5
    You can also create a gradle.properties file in libs/ with `kapt.incremental.apt=false` too as described in the issue as a workaround. It worked for me. – Necrontyr Aug 27 '19 at 18:50
  • 2
    @Necrontyr, your suggestion really worked out. Thanks a lot – Shax Aug 28 '19 at 05:11

14 Answers14

214

Just add this line to you gradle.properties:

kapt.incremental.apt=true
Draken
  • 3,134
  • 13
  • 34
  • 54
Ali Ahmed
  • 2,425
  • 2
  • 8
  • 13
  • 15
    This is a better option that the accepted answer. For those who need to understand and get into more details, refer this link : https://medium.com/avast-engineering/making-incremental-kapt-work-speed-up-your-kotlin-projects-539db1a771cf – Abhimanyu Sep 07 '19 at 18:42
  • 6
    faild for me too. – steven smith Sep 16 '19 at 18:41
  • 1
    is anyone whats the reason why it's happening here? – Omer Nov 15 '19 at 01:17
  • I recently enabled data binding to my android (kotlin) project and started getting this warning. Adding the property as stated above worked for me. Also using the latest versions of everything, e.g. all dependencies, compilers, build tools, SDKs, etc. – Gail Jan 29 '20 at 22:32
  • 9
    Doing just this, did not work for me. I had to also edit my build.gradle file as described in the [documentation for the Room library](https://developer.android.com/jetpack/androidx/releases/room#compiler-options). – Mike F May 16 '20 at 22:41
159

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"
        }
    }
Dimas Mendes
  • 2,664
  • 1
  • 21
  • 19
  • 8
    This one should be accepted as kapt.incremental.apt=true is something that will be missing when including Room in your project. That one is not even mentioned in Android docs for [Room](https://developer.android.com/jetpack/androidx/releases/room#declaring_dependencies) – sela Oct 06 '19 at 14:22
  • 1
    This answer helped me as I was using `androidx.lifecycle:lifecycle-extensions` in version 2.1.0 and after switching to 2.2.0-beta01 the warning went away! – simne7 Oct 22 '19 at 13:43
  • 2
    @simne7 check out my edit in the end. version 2.2.0 is released =) you can upgrade it already to access the incremental processing feature and boost your build. – Dimas Mendes Oct 24 '19 at 14:51
  • Would enabling `android.buildcache=true` make it faster? – IgorGanapolsky Mar 15 '20 at 17:52
  • 1
    @IgorGanapolsky according to Google Developers Website, `Projects using Android plugin 2.3.0 and higher enable the build cache by default (unless you explicitly disable the build cache)`. So it doesn't make sense to enable it as it is enabled by default. – Dimas Mendes Mar 16 '20 at 16:06
81

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.

Mücahid Kambur
  • 1,610
  • 13
  • 10
  • 85
    The bug mentioned by @Necrontyr is unrelated to the warning. The warning is actually intended and going down to 1.3.41 just hides the warning but the problem stays the same, if not worse. People might think that because they turned on incremental annotation processing it will make things faster. But the truth is that if any of the annotation processors are not incremental then none of them will be processed incrementally. This is a friendly reminder that will point out what library is the culprit. – Antimonit Sep 16 '19 at 08:19
  • 30
    Using an outdated library version isn't a solution. – Andrew Koster Nov 13 '19 at 21:00
  • 5
    Is this still the case with Kotlin `1.3.70`? – IgorGanapolsky Mar 15 '20 at 17:50
  • 3
    I'm using Kotlin 1.3.72 and still face this problem? – Anbuselvan Rocky May 23 '20 at 18:51
  • 9
    I am also facing this issue 1.3.72 any solution guys ? – hiashutoshsingh Jun 07 '20 at 14:32
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.

Cris
  • 774
  • 9
  • 32
Alberto Gaona
  • 2,427
  • 25
  • 20
32

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
Community
  • 1
  • 1
Shomu
  • 2,734
  • 24
  • 32
30

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 
smdufb
  • 555
  • 4
  • 19
10

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
Jacques.S
  • 3,262
  • 2
  • 21
  • 27
  • 2
    I am not so sure about `android.lifecycleProcessor.incremental=true`, it doesn't seem to be documented anywhere – Daniel Wilson Oct 03 '19 at 09:05
  • I am not sure either, but I tried it on a hunch and the compiler stopped telling me that the lifecycleProcessor library did not have incremental processing enabled. – Jacques.S Oct 03 '19 at 09:57
8

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.

  • 1
    THIS actually worked. Set it to FALSE people! thanks – Sakiboy Sep 20 '19 at 20:18
  • And what will happen? Will it compile faster or simply hide the warning? – CoolMind Sep 26 '19 at 13:46
  • 1
    @CoolMind You would be disabling incremental annotation processing, something that is anyway not going to happen if any of your dependencies don't support it. So, the warning goes away and there's no change in the build process from before. – D. C. Christopher Sep 27 '19 at 14:28
  • 2
    Surprisingly setting `kapt.incremental.apt=false` helped me, I no more getting the error – Rakhi Dhavale Oct 14 '19 at 13:56
  • 5
    You have no more error but now you have no incremental processing :) – JustAnotherCoder Nov 07 '19 at 15:15
  • @JustAnotherCoder and for anyone else who comes by this comment ... if you were getting the above warning, you were _already_ without incremental processing. If you end up updating your other modules and you got them all to support incremental processing, _then_ you could go back and set the line to true (or remove it entirely) so that incremental annotation processing is requested again. – D. C. Christopher Jan 15 '20 at 20:23
  • +1 The only logical answer. Warning tells, that some feature was requested, but is not supported. The only thing we can do it "not to request this feature". – Dmitrii Semikin Nov 30 '20 at 13:22
2

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"]
            }
        }
coroutineDispatcher
  • 7,718
  • 6
  • 30
  • 58
1

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.

Anigif
  • 872
  • 8
  • 17
  • Why are you getting rid of `kapt`? – IgorGanapolsky Mar 15 '20 at 18:06
  • @IgorGanapolsky That is what is suggested by the AndroidX Lifecycle if you're using Java 8. See more here: https://developer.android.com/jetpack/androidx/releases/lifecycle#declaring_dependencies – Anigif Mar 16 '20 at 11:09
  • `kapt` is essential for Kotlin – IgorGanapolsky Mar 16 '20 at 14:04
  • 1
    Only if the lib requires it. According to this page the annotations will be deprecated once Java 8 get more mainstream on Android, so they recommend `common-java8` if possible: https://developer.android.com/reference/androidx/lifecycle/Lifecycle – Anigif Mar 16 '20 at 14:23
  • Interesting. They don't mention `kapt` in particular though... – IgorGanapolsky Mar 16 '20 at 14:37
  • I was thinking about the same, but in the other link they're pretty clear about using `common-java8` *instead* of `lifecycle-compiler` if using Java 8 – Anigif Mar 16 '20 at 17:04
1

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.

Sourav Roy
  • 323
  • 4
  • 12
1

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.

Sefa Keleş
  • 81
  • 1
  • 6
0

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.

Hasan Kucuk
  • 2,433
  • 6
  • 19
  • 41
0

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?,
bazcava
  • 23
  • 8