How to get rid of Incremental annotation processing requested warning?

后端 未结 13 811
一生所求
一生所求 2020-12-04 08:27

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

相关标签:
13条回答
  • 2020-12-04 08:40

    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.

    0 讨论(0)
  • 2020-12-04 08:44

    Just add this line to you gradle.properties:

    kapt.incremental.apt=true
    
    0 讨论(0)
  • 2020-12-04 08:46

    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.

    0 讨论(0)
  • 2020-12-04 08:49

    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 
    
    0 讨论(0)
  • 2020-12-04 08:49

    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
    
    0 讨论(0)
  • 2020-12-04 08:50

    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.

    0 讨论(0)
提交回复
热议问题