Android-nRF-Mesh-Library
Android-nRF-Mesh-Library copied to clipboard
FOREIGN KEY constraint failed on loading of default mesh network
Hi @dinesharjani and @philips77,
In my KMM app, which is consuming the Android-nRF-Mesh-Library, after reception of MeshManagerCallabacks
- onNetworkUpdated
- onNetworkLoaded
nRF Mesh library is getting a fatal exception accessing the DB. I'm getting this exception during the verify initial startup and initialization of mesh manager API. It seems like the database is missing required records that violate foreign key dependencies in the Room database used by the library. Furthermore, is there any way to avoid the default creation of a new mesh network by default during library initialization? Another point is: where is stored this DB? Can I look directly to it? NRF Mesh Android/iOS provide some API in order to reset this DB? Which is the password to use in order to export mesh_network_database.db? And where I can it?
NOTE: on my phone I've also installed an instance of "nRF Mesh" app for Android.
Platform details:
implementation("androidx.sqlite:sqlite-bundled:2.5.0-alpha10")
Logs / Screenshots Exception stack trace:
2024-10-25 18:17:01.980 22885-22942 AndroidRuntime app E FATAL EXCEPTION:
pool-3-thread-2
Process: app, PID: 22885
android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787 SQLITE_CONSTRAINT_FOREIGNKEY)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:961)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:89)
at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.android.kt:38)
at androidx.room.EntityInsertionAdapter.insertAndReturnId(EntityInsertionAdapter.android.kt:100)
at no.nordicsemi.android.mesh.data.ApplicationKeyDao_Impl.insert(ApplicationKeyDao_Impl.java:112)
at no.nordicsemi.android.mesh.MeshNetworkDb.lambda$insert$11(MeshNetworkDb.java:248)
at no.nordicsemi.android.mesh.MeshNetworkDb$$ExternalSyntheticLambda28.run(Unknown Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Hi, let's wait for @roshanrajaratnam to come back.
Btw, you may check the database using Android Studio. Have a look at: https://developer.android.com/studio/inspect/database
Hi @philips77! We are facing this issue as well in our app and it started to get the most frequent crash in our application. Are there any updates in regards of this issue (how or why it occurs) or when it will be fixed? To us it seems to be caused by deleting old mesh networks and importing new mesh networks into the mesh database.
Hi, We didn't touch anything related to a database in the recent releases. I'm not sure why are you getting the error.
However, we are almost ready with the release of a successor of this library, a mesh library 100% in Kotlin, with grately improved API and brand new nRF Mesh app. The API is very similar to the one we have in iOS version, which should also make buiding wrappers for cross-platform easier. I'll notify you when the repo becomes public.
@philips77 Awesome thank you. Looking forward to the Kotlin release.
Hi @philips77! We also sometimes face this issue in our app. I understand you guys won't work on this problem in favor of the new Kotlin library?
Please forgive us delays caused by the vacation period. We are focusing on the new library, but will try to keep the old one usable as well and fix bugs if necessary. Regarding this issue, we need to wait until the main dev is back, sorry for the inconvienience.