我刚刚开始使用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'
// …
Run Code Online (Sandbox Code Playgroud) 我已经看过这个答案和这个网站上的其他人,并使用谷歌,但我还没有找到适合这个问题的答案。这是最新版本的 KAPT 列出的剩余的非增量注释处理器:
Incremental annotation processing requested, but support is disabled because the following processors are not incremental: android.databinding.annotationprocessor.ProcessDataBinding (NON_INCREMENTAL)
Run Code Online (Sandbox Code Playgroud)
请注意,我已迁移到 AndroidX 并使用 AGP 3.4.1(无法升级到 AGP 3.5.x)和 Gradle 5.5。任何帮助将非常感激。
我是android数据绑定的新手。我想将多个 SeekBars 绑定到一个浮点数集合,例如
SeekBar1.progress <---> modelArray[0]
SeekBar2.progress <---> modelArray[1]
...
Run Code Online (Sandbox Code Playgroud)
由于SeekBar的进度是Int类型,我觉得用Converter会更好,下面是转换器代码:
import android.databinding.InverseMethod
import android.util.Log
import kotlin.math.roundToInt
class Converter {
@InverseMethod("progressToFloat")
fun floatToProgress(value: Float): Int {
val result = (value * 100.0f).roundToInt()
Log.i("MODEL", "convert $value to $result(Int)")
return result
}
fun progressToFloat(value: Int): Float {
return value.toFloat()/100.0f
}
}
Run Code Online (Sandbox Code Playgroud)
模型结构如下所示:
class Model {
val params by lazy {
ObservableArrayMap<Int, Float>()
}
//....
}
Run Code Online (Sandbox Code Playgroud)
我的xml如下:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data class="MyBinding">
<variable name="Converter" type="com.mypackage.model.Converter"></variable>
<variable
name="Converter"
type="com.mypackage.model.Converter"></variable>
<variable
name="model"
type="com.mypackage.model.Model"></variable>
</data> …
Run Code Online (Sandbox Code Playgroud) data-binding android kotlin android-databinding two-way-binding