Sha*_*hax 73 android android-lifecycle android-room
我刚刚开始使用android开发并尝试使用Room库。从昨天开始我就面临着这个警告信息
w:[kapt]请求了增量注释处理,但是由于以下处理器不是增量处理器,因此禁用了支持:androidx.lifecycle.LifecycleProcessor(NON_INCREMENTAL),androidx.room.RoomProcessor(NON_INCREMENTAL)。
我已经尝试研究和修复,但无法避免此错误,这是我的grale.build文件。请提出建议/建议我在做什么错。
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'
}
Run Code Online (Sandbox Code Playgroud)
小智 74
如@Necrontyr所述,1.3.50的kotlin-gradle-plugin版本中存在一个错误。只需将build.gradle(Project)中的kotlin_version降级到1.3.41。
Ali*_*med 68
只需将此行添加到您的gradle.properties中:
kapt.incremental.apt=true
Run Code Online (Sandbox Code Playgroud)
Dim*_*des 37
真正的问题是,增量处理使处理速度更快,但是如果任何注释处理器不是增量处理器,那么它们中的任何一个都不会被实际处理。
增量处理的目的是什么?
从1.3.30+版本开始,增量处理允许每次发生更改时都不再完全处理模块,从而使构建过程具有更好的性能:
此版本的主要关注领域是Kotlin / Native,KAPT性能以及IntelliJ IDEA的改进。
带有kapt编译器插件的Kotlin支持注释处理器(请参阅JSR 269)。简而言之,您可以在Kotlin项目中使用Dagger或Data Binding之类的库。
如何解决房间增量处理?
默认情况下,Room增量注释处理器是禁用的。这是一个已知问题,在此进行描述。他们打算在2.2.0版上修复它。您可以等待更新,也可以通过以下设置启用它来摆脱警告:
在gradle.properties文件中:
kapt.incremental.apt=true
(可选步骤)
允许数据绑定是增量的:
android.databinding.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"
}
Run Code Online (Sandbox Code Playgroud)
和
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental":"true"]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Kotlin DSL版本:
dependencies {
...
implementation("androidx.room:room-runtime:2.2.0-rc01")
kapt("androidx.room:room-compiler:2.2.0-rc01")
}
Run Code Online (Sandbox Code Playgroud)
和
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = mapOf("room.incremental" to "true")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
十月9,2019
释放 androidx.room:room-*:2.2.0 。
Gradle增量注释处理器:Room现在是Gradle隔离注释处理器,可通过处理器选项room.incremental启用可增量性。
Sho*_*omu 28
使用 Kotlin 1.3.31 或更新的 Kotlin 1.3.30 发布
在你的 android kotlin 项目 gradle.properties 文件中
# 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
Run Code Online (Sandbox Code Playgroud)
Alb*_*ona 16
从会议室文档:
“房间具有以下注释处理器选项... room.incremental:启用Gradle增量注释处理器。”
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true",
"room.expandProjection":"true"]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
确保将会议室版本更新为2.2.x或更高版本。
这里的许多其他答案掩盖了错误或禁用了增量处理,而不是按照您想要的方式使其真正起作用。
您可以为gradle.properties文件中的特定库启用增量处理。只需添加这些设置,或者添加任何与引发错误的库相匹配的设置:
android.databinding.incremental=true
android.lifecycleProcessor.incremental=true
Run Code Online (Sandbox Code Playgroud)
小智 7
如果它抱怨“请求增量注释处理,但由于以下处理器不是增量而禁用支持”,那么在 gradle.properties 中将“kapt.incremental.apt”设置为“true”(在不同的答案中提到)是反的直觉的。您需要将其设置为“false”。那是为我做的。
这是您可以用来解决此问题并显着减少构建时间的列表。
在您的build.gradle(模块)文件中:
android {
...
defaultConfig {
...
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
arg("room.incremental", "true")
arg("room.expandProjection", "true")
}
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
在您的gradle.properties文件中:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20588 次 |
| 最近记录: |