В моем текущем Android-приложении есть требование извлекать строки из моей локальной базы данных Sqlite с полем подсчета.
Я понимаю, что мне нужно, чтобы в моей сущности DO было определено это поле подсчета и @Ignore (ed)
Я поискал в Google и нашел страницу
@Entity
data class User(
@PrimaryKey val id: Int,
val firstName: String?,
val lastName: String?,
@Ignore val picture: Bitmap?
)
Однако, когда я копирую и вставляю этот точный код Kotlin в свое приложение, он не может быть создан с этими исключениями
database_room:kaptStagingDebugKotlin FAILED
e: /Users/rossulbricht/projects/silkroad/database_room/build/tmp/kapt3/stubs/stagingDebug/org/dread/pirate/database_room/model/User.java:7: error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
public final class User {
^
Tried the following constructors but they failed to match:
User(int,java.lang.String,java.lang.String,android.graphics.Bitmap) -> [param:id -> matched field:id, param:firstName -> matched field:firstName, param:lastName -> matched field:lastName, param:picture -> matched field:unmatched]
e: /Users/rossulbricht/projects/silkroad/database_room/build/tmp/kapt3/stubs/stagingDebug/org/dread/pirate/database_room/model/User.java:9: error: Cannot find setter for field.
private final int id = 0;
^
e: /Users/rossulbricht/projects/silkroad/database_room/build/tmp/kapt3/stubs/stagingDebug/org/dread/pirate/database_room/model/User.java:11: error: Cannot find setter for field.
private final java.lang.String firstName = null;
^
e: /Users/rossulbricht/projects/silkroad/database_room/build/tmp/kapt3/stubs/stagingDebug/org/dread/pirate/database_room/model/User.java:13: error: Cannot find setter for field.
private final java.lang.String lastName = null;
^
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
> Task :networking:mergeStagingDebugNativeLibs
> Task :android_idplus:generateStagingDebugRFile
> Task :networking:processStagingDebugManifest
FAILURE: Build failed with an exception.
Мои вопросы ...
Как игнорировать столбцы в сущности комнаты классов данных Kotlin?
Почему не работают примеры Google Android?
Я использую
Android Studio 3.5
Build #AI-191.8026.42.35.5791312, built on August 9, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.6
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://sdk.smartlook.com/android/release"
}
}
}
ext {
compileSdkVersion = 28
targetSdkVersion = 28
minSdkVersion = 21
supportLibVersion = '1.1.0-beta01'
coreKtx = '1.2.0-alpha04'
materialMaterial = '1.1.0-alpha10'
legacySupportV4 = "1.0.0"
recyclerView = '1.1.0-beta04'
lifecycleExtensions = '2.2.0-alpha04'
playServicesAuthVersion = "16.0.1"
archLifecycleVersion = '2.2.0-alpha04'
roomVersion = '2.2.0-rc01'
archPagingVersion = '2.1.0'
archWorkerRuntimeVersion = '2.3.0-alpha01'
constraintLayoutVersion = '2.0.0-beta2'
browserVersion = '1.0.0'
appCompatVersion = '1.1.0'
junitVersion = "4.12"
testRunnerVersion = '1.1.0-alpha4'
espressoTestCoreVersion = '3.1.0-alpha4'
uiautomatorVersion = '2.2.0-alpha4'
leakcanaryVersion = "1.6.1"
commonsTextVersion = '1.7'
rxbinding2Version = "2.2.0"
picassoVersion = "2.71828"
retrofit2Version = '2.6.1'
rxAndroidVersion = '2.1.1'
rxJavaVersion = '2.2.11'
jacksonKotlinVersion = '2.10.0.pr1'
okhttp3Version = '4.1.1'
okioVersion = '2.4.0'
jakewRxrelay2Version = '2.1.0'
daggerVersion = '2.24'
numbusJoseJwtVersion = '7.1'
interComVersion = "5.4.1"
guavaAndroidVersion = "28.1-android"
}
task clean(type: Delete) {
delete rootProject.buildDir
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}