本文主要是介绍Android Room数据库异常: Room cannot verify the data integrity.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 一、前言
- 二、错误信息如下
- 三、参考链接
一、前言
在Room数据库结构变动的情况下,如果没有进行Room数据库升级迁移,则会报错Room cannot verify the data integrity.
。在实际开发过程中,数据库结构会经常变化,直到发版。一般来说卸载即可重新安装,但是有时候即使卸载了再安装依然会出现这个错误。这时候通常重启设备再重新安装即可,然而
再后面即使数据库没有更改多次安装还是有概率出现,一旦出现,只能重启。查阅多种资料,最终发现通过禁用备份功能可以解决该问题。猜测是备份功能会自动把之前旧的数据库版本更新下来然后与当前新版本数据库产生了冲突
<applicationandroid: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]
三、参考链接
- 该链接记录了Room数据库的自身漏洞
https://issuetracker.google.com/issues/221101259 - 该链接记录了Room数据库的自身漏洞
https://github.com/android/codelab-android-workmanager/issues/283 - 该链接记录了一些解决room数据库版本冲突的方案
https://copyprogramming.com/howto/room-cannot-verify-the-data-integrity-in-android - 解决:room无论如何怎么修改数据库版本都报错java.lang.IllegalStateException: Room cannot verify the data integrity
https://blog.csdn.net/qq_41888672/article/details/127162613
这篇关于Android Room数据库异常: Room cannot verify the data integrity.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!