google-developer-training / basic-android-kotlin-compose-training-inventory-app

Apache License 2.0
77 stars 84 forks source link

Read and update data using Room Runtime Problem #147

Closed pensysco closed 1 week ago

pensysco commented 2 weeks ago

URL of codelab: https://github.com/google-developer-training/basic-android-kotlin-compose-training-inventory-app/tree/main

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found? It was occurring earlier in the above titled codelab but definitely occurs after the solution code in step 9 is loaded, compiled and then run. The crash occurs once the test device has been launched apparently when a composable loading the database does a validity test.

Describe the problem I keep getting this runtime exception error (copied from logcat):

2024-09-25 17:14:58.417 27098-27098 AndroidRuntime pid-27098

E FATAL EXCEPTION: main Process: com.example.inventory, PID: 27098 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. Expected identity hash: 8f1f4a57c15a39434577c64bd197bfab, found: aede725c80c21d9dad3ea443bd9bc21b at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.kt:146) at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.kt:127) at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.kt:287) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:427) at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:316) at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase(FrameworkSQLiteOpenHelper.kt:232) at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase(FrameworkSQLiteOpenHelper.kt:190) at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase(FrameworkSQLiteOpenHelper.kt:151) at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.kt:104) at androidx.room.RoomDatabase.inTransaction(RoomDatabase.kt:632) at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.kt:451) at androidx.room.RoomDatabase.query(RoomDatabase.kt:480) at androidx.room.util.DBUtil.query(DBUtil.kt:75) at com.example.inventory.data.ItemDao_Impl$7.call(ItemDao_Impl.java:151) at com.example.inventory.data.ItemDao_Impl$7.call(ItemDao_Impl.java:147) at androidx.room.CoroutinesRoom$Companion$createFlow$1$1$1.invokeSuspend(CoroutinesRoom.kt:129) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@fb2be7d, Dispatchers.Main.immediate]

Steps to reproduce?

  1. Go to... step 9 and load the solution code into Android Studio. Compiles Ok. Run the app on device (see below) and it crashes right away.
  2. Click on...
  3. See error...

Versions Android Studio version: Android Studio Koala | 2024.1.1 Patch 2 Build #AI-241.18034.62.2411.12169540, built on August 1, 2024 Runtime version: 17.0.11+0--11852314 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 8 Registry: debugger.watches.in.variables=false Non-Bundled Plugins: com.genymotion.idea (2.0.1)

API version of the emulator: None, using Motorola Moto g stylus device running Android 11, API 30 Build RPRS31.Q1-56-9-16-2

Additional information Include screenshots if they would be useful in clarifying the problem. See above

pensysco commented 1 week ago

The problem seems to have been caused by running the SQL example just before running the Inventory example. The SQL example dates back to the Gradle environment in 2022 and apparently left the room database in my cell phone memory. The Inventory app appears to have run a later version of Room and picked up the wrong has code. Uninstalling the SQL example appears to have solved this problem.