Android Room数据库异常: Room cannot verify the data integrity.

一、前言

在Room数据库结构变动的情况下,如果没有进行Room数据库升级迁移,则会报错Room cannot verify the data integrity.。在实际开发过程中,数据库结构会经常变化,直到发版。一般来说卸载即可重新安装,但是有时候即使卸载了再安装依然会出现这个错误。这时候通常重启设备再重新安装即可,然而
再后面即使数据库没有更改多次安装还是有概率出现,一旦出现,只能重启。查阅多种资料,最终发现通过禁用备份功能可以解决该问题。猜测是备份功能会自动把之前旧的数据库版本更新下来然后与当前新版本数据库产生了冲突

<application
        android:allowBackup="false"
        tools:replace="android:allowBackup">

二、错误信息如下

01-29 11:05:00.595 17133 17133 E AndroidRuntime: FATAL EXCEPTION: main
01-29 11:05:00.595 17133 17133 E AndroidRuntime: java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:55)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:4)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:11)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:447)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:332)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:5)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:5)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:3)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:1)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.FlowKt__MergeKt$mapLatest$1.invokeSuspend(Merge.kt:49)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.FlowKt__MergeKt$mapLatest$1.invoke(Merge.kt:2)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.FlowKt__MergeKt$mapLatest$1.invoke(Merge.kt:1)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invokeSuspend(Merge.kt:35)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invoke(Merge.kt:2)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invoke(Merge.kt:1)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:23)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.f.c(Unknown Source:35)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1.emit(Merge.kt:109)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.p1.m(SharedFlow.kt:200)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.flow.SharedFlowImpl$collect$1.invokeSuspend(SharedFlow.kt:13)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:9)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.o0.run(DispatchedTask.kt:124)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.internal.g$a.run(LimitedDispatcher.kt:4)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at a8.i.run(Tasks.kt:3)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	at kotlinx.coroutines.scheduling.CoroutineScheduler$b.run(CoroutineScheduler.kt:101)
01-29 11:05:00.595 17133 17133 E AndroidRuntime: 	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [z1{
   Cancelling}@d556480, Dispatchers.Main]

三、参考链接

  1. 该链接记录了Room数据库的自身漏洞
    https://issuetracker.google.com/issues/221101259
  2. 该链接记录了Room数据库的自身漏洞
    https://github.com/android/codelab-android-workmanager/issues/283
  3. 该链接记录了一些解决room数据库版本冲突的方案
    https://copyprogramming.com/howto/room-cannot-verify-the-data-integrity-in-android
  4. 解决:room无论如何怎么修改数据库版本都报错java.lang.IllegalStateException: Room cannot verify the data integrity
    https://blog.csdn.net/qq_41888672/article/details/127162613

相关推荐

  1. SparkSQL异常数据清洗API

    2024-01-31 12:40:05       21 阅读
  2. 解决zabbix连接mysql 8数据库异常问题

    2024-01-31 12:40:05       39 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-31 12:40:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-31 12:40:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-31 12:40:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-31 12:40:05       18 阅读

热门阅读

  1. Android --- Content Provider是使用示例,通俗易懂

    2024-01-31 12:40:05       34 阅读
  2. flutter 修改状态栏

    2024-01-31 12:40:05       31 阅读
  3. mongodb config

    2024-01-31 12:40:05       31 阅读
  4. 知识价值1-github站点域名

    2024-01-31 12:40:05       35 阅读
  5. Python - 整理 MySQL 慢查询日志

    2024-01-31 12:40:05       38 阅读
  6. Blender Object 的 name 字段不是 string

    2024-01-31 12:40:05       23 阅读
  7. C Primer Plus(第六版)14.17 复习题 第5题

    2024-01-31 12:40:05       26 阅读
  8. 【Spark系列5】Dataframe下常用算子API

    2024-01-31 12:40:05       29 阅读
  9. C++学习——模板类的使用:自定义数组

    2024-01-31 12:40:05       36 阅读
  10. C语言中大小写字母的转化

    2024-01-31 12:40:05       30 阅读