提问者:小点点

如何摆脱增量注释处理请求的警告?


刚开始用Android开发,尝试用房库。从昨天开始,我就面对这个警告信息

w: [kapt]请求增量注释处理,但由于以下处理器不是增量的,因此支持被禁用:androidx.lifecycle。生命周期处理器(非增量),androidx.room。房间处理器(非增量)。

我尝试过研究和修复,但无法避免这个错误。构建文件。请就我做错了什么提出建议。

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

共3个答案

匿名用户

只需将这一行添加到gradle.properties:

kapt.incremental.apt=true

匿名用户

真正的问题是,增量处理使事情更快,但如果任何注释处理器都是非增量的,那么它们实际上都不会以这种方式处理。

增量处理的目的是什么?

从版本1.3.30开始,增量处理允许模块在每次发生变化时不再被完全处理,从而使构建过程具有更好的性能:

此版本的主要关注领域是静态编程语言/本机、KAPT性能以及IntelliJ IDEA的改进。

静态编程语言留档:

注释处理器(参见 JSR 269)在 Kotlin 中通过 kapt 编译器插件受支持。简而言之,您可以在 Kotlin 项目中使用匕首或数据绑定等库。

如何修复房间增量处理?

默认情况下,房间增量注释处理器处于禁用状态。这是一个已知的问题,本文对此进行了描述。他们打算在2.2.0版上修复它。您可以等待更新,也可以通过设置:

在gradle.properties文件中:

kapt.incremental.apt=真

(可选步骤)

以允许增量数据绑定:

< code > Android . data binding . incremental = true

对于更快的构建:

kapt.use.worker.api=true

如果只进行少量更改,构建时间将大大缩短:

kapt.include.compile.classpath=false

(回到主题)

在项目build.gradle中,添加必要的依赖项(Groovy):

dependencies {
    ...
    implementation "androidx.room:room-runtime:2.2.0-rc01"
    annotationProcessor "androidx.room:room-compiler:2.2.0-rc01"
}

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.incremental":"true"]
            }
        }
    }
}

静态编程语言DSL版本:

dependencies {
    ...
    implementation("androidx.room:room-runtime:2.2.0-rc01")
    kapt("androidx.room:room-compiler:2.2.0-rc01")
}

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = mapOf("room.incremental" to "true")
            }
        }
    } 
}

2019年10月9日

androidx.room:room-*:2.2.0发布。

Gradle增量注释处理器:Room现在是一个Gradle隔离注释处理器,可以通过处理器选项启用增量room.incremental.

最新更新:

对于最新的科特林DSL版本,请使用

    javaCompileOptions {
        annotationProcessorOptions {
            arguments["room.incremental"] = "true"
        }
    }

匿名用户

正如@Necrontyr提到的,kotlin gradle插件版本1.3.50中有一个bug。只需在构建中降级kotlin_version。gradle(项目)至1.3.41。