我已经在我的应用程序中使用了房间数据库。现在我已经将我的项目迁移到androidX,因此依赖关系被改变了。
现在,当我添加一个表并试图运行项目时,我得到了一个多个文件的错误:
error: cannot find symbol class BR
@Keep
@Entity
public class Notification {
private String title;
private String body;
public Notification(String title, String body) {
this.title = title;
this.body = body;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
}
public abstract class NotificationDao {
@Insert(onConflict = REPLACE)
public abstract void insert(Notification notification);
@Query("DELETE FROM Notification")
public abstract void deleteAll();
}
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS Notification (`title` TEXT, `body` TEXT)");
}
};
Room.databaseBuilder(
application,
MyDatabase.class,
Configuration.DB_NAME
).addMigrations(MyDatabase.MIGRATION_1_2).build();
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 211990017
versionName "2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Write out the current schema of Room
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString(),]
}
}
vectorDrawables.useSupportLibrary = true
project.archivesBaseName = "xxxx";
multiDexEnabled true
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -fexceptions"
arguments "-DANDROID_TOOLCHAIN=clang",
"-DANDROID_STL=c++_shared",
"-DANDROID_PLATFORM=android-21"
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
signingConfigs {
release {
storeFile file("keystores/xxxx")
storePassword "xxxx"
keyAlias "xxxx"
keyPassword "xxxx"
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles fileTree(dir: "proguard", include: ["*.pro"]).asList().toArray()
proguardFiles getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles fileTree(dir: "proguard", include: ["*.pro"]).asList().toArray()
proguardFiles getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
}
dataBinding {
enabled true
}
buildToolsVersion '28.0.3'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "environment"
productFlavors {
development {
applicationId "com.emproto.xxxx"
resValue "string", "content_provider", "com.xxx.xxxx.fileprovider"
}
production {
applicationId "com.xxxx"
resValue "string", "content_provider", "com.xxxx.fileprovider"
}
}
splits {
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable true
// By default all ABIs are included, so use reset() and include to specify that we only
// want APKs for x86 and x86_64.
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "x86", "x86_64", "arm64-v8a", "armeabi-v7a"
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk true
}
}
}
ext.abiCodes = ['x86': 1, 'x86_64': 2, 'armeabi-v7a': 3, 'arm64-v8a': 4]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def baseVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
if (baseVersionCode != null) {
output.versionCodeOverride = Integer.valueOf(baseVersionCode + variant.versionCode)
}
}
}
ext {
retrofitVersion = '2.3.0'
daggerVersion = '2.11'
supportLibVersion = '28.0.0'
googleLibVersion = '16.0.1'
frescoLibVersion = '2.0.0'
moEngageVersion = '9.8.02'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.exifinterface:exifinterface:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
/*Dagger 2 is a fully static and compile time dependency injection framework*/
implementation "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
implementation 'javax.annotation:jsr250-api:1.0'
/*LiveData and ViewModel*/
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
/*
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
*/
/*Room*/
implementation 'androidx.room:room-runtime:2.2.3'
annotationProcessor 'androidx.room:room-compiler:2.2.3'
// Java8 support for Lifecycles
implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0'
/*Retrofit*/
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
/*For loading images from network*/
implementation "com.facebook.fresco:fresco:$frescoLibVersion"
implementation "com.facebook.fresco:imagepipeline-okhttp3:$frescoLibVersion"
/*For the left menu*/
implementation 'com.yarolegovich:sliding-root-nav:1.1.0'
/*For the typing indicator*/
implementation 'com.github.channguyen:adv:1.0.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
/*For Graphs */
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
/*For firebase push notifications */
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "com.google.firebase:firebase-core:16.0.6"
/*For Database debugging */
// debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
/*For S - Health */
implementation files('libs/s-health/samsung-health-data-v1.3.0.jar')
implementation files('libs/s-health/sdk-v1.0.0.jar')
/*For Google-Fit */
implementation "com.google.android.gms:play-services-fitness:$googleLibVersion"
implementation "com.google.android.gms:play-services-auth:$googleLibVersion"
/*Circular floating action bar*/
implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
// For animated GIF support
implementation "com.facebook.fresco:animated-gif:$frescoLibVersion"
/*Circular seekbar - Feelings*/
implementation 'com.github.JesusM:HoloCircleSeekBar:v2.2.2'
/*Circular Layout - Feelings*/
implementation 'com.github.andreilisun:circular-layout:1.0'
/*For offline log synchronization*/
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
/*Wheel picker - RecordCholesterol*/
implementation 'com.weigan:loopView:0.1.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') {
transitive = true;
}
/*Image Cropper - Profile Fragment*/
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
/*PDF Viewer - Prescription/Report */
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
api 'com.thedesigncycle.ui:views:0.3.1'
implementation 'com.ogaclejapan.smarttablayout:library:1.6.1@aar'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
implementation files('libs/omron/jp.co.omron.healthcare.omoron_connect.wrapper-1.3.jar')
implementation 'com.appsee:appsee-android:+'
implementation 'com.github.florent37:viewtooltip:1.1.6'
implementation 'com.asksira.android:cameraviewplus:0.9.5'
implementation 'me.zhanghai.android.materialratingbar:library:1.3.1'
implementation 'com.priyankvex:smarttextview:1.0.1'
implementation 'com.github.flipkart-incubator:android-inline-youtube-view:1.0.3'
implementation 'com.github.varunest:sparkbutton:1.0.6'
implementation 'io.branch.sdk.android:library:3.2.0'
//foo transitions in trel home(doctor names)
implementation "com.andkulikov:transitionseverywhere:1.8.1"
//AppsFlyer
implementation 'com.appsflyer:af-android-sdk:4.10.3'
implementation 'com.android.installreferrer:installreferrer:1.0'
//picasso image loading lib
implementation 'com.squareup.picasso:picasso:2.5.2'
//Facebook analytics dependency
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
//Moengage dependency
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.moengage:moe-android-sdk:$moEngageVersion"
}
apply plugin: 'com.google.gms.google-services'
如何修复错误?
没有在模型类中添加主键是导致问题的原因。我认为更具体的错误信息应该有来自android Studio方面的关于房间数据库的信息。
我尝试在Android房间中附加数据库,如下所示:如何从Android房间中的多个数据库中进行选择(如何附加数据库),但在构建项目时出现错误:错误:查询有问题:[SQLITE\u错误]SQL错误或缺少数据库(没有这样的表:database.table)错误 当我添加@SkipQuery验证时,错误发生了变化:错误:不确定如何将游标转换为此方法的返回类型。 当我从查询中删除“myDatabase.”
问题内容: 这是我的第一篇文章!希望您能帮帮我!:-) 我使用了NotePadExample提供的来自开发人员文档的代码来创建数据库。现在,我想添加第二个表来存储不同的数据。我可以毫无问题地添加注释,并且注释表的创建方式与路由表类似。我只是简单地“复制”并编辑了给定的代码,但是当我尝试插入到新表中时,出现错误消息: “ 0ERROR / Database(370):android.database
我正在使用Room作为应用程序的数据库。我正在用改型从服务器上获取数据。场景是,我有一个名为Photo的类,并用实体进行注释,以供room使用,我使用这个类使用retroft映射API的响应。我需要使用同一个类创建两个表,例如:最新的照片表和流行的照片表。我怎样才能做到这一点。 > 我不想创建一个新的类并使它从另一个类扩展 我有一个想法,通过插入一个新的列,表明照片是流行的或最新的,但我不知道如何
问题内容: 尝试添加另一个列表时抛出List.addAll 。 在循环中,我在做, 从文件中读取 supportType 。 但是第2行抛出一个,但是我无法确定为什么? 我要在列表中添加另一个列表,那么为什么不支持此操作? 问题答案: 返回一个固定大小的列表,该列表由数组支持,并且您不能向其中添加元素。 您可以创建一个可修改的列表以进行工作:
BidsItem类 如果有人告诉我我需要做什么,或者至少向什么方向前进,我将非常感激
问题内容: 我在这个例外上受苦。我的代码有什么问题?我只想将Person的重复名称分开 这是堆栈跟踪 问题答案: 您无法修改要迭代的对象。那可能会抛出一个。尽管有时可能会工作,但不能保证每次都能工作。 如果要添加或从列表中删除某些内容,则需要使用或。并使用方法在列表中添加任何内容。即使在您的中,如果您尝试使用或,您也会得到该异常,因为那没有任何区别。您应该使用的方法。