Fixed
Status Update
Comments
da...@google.com <da...@google.com>
da...@google.com <da...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
Author: Daniel Santiago Rivera <
Link:
Use Context.getDatabasePath() when a driver is configured.
Expand for full commit details
Use Context.getDatabasePath() when a driver is configured.
This helps users migrating to driver APIs that use simple database names and expect Room to figure out the directory to store the database, for which the SupportSQLiteOpenHelper is responsible off when no driver is used.
Since getDatabasePath() does some IO, a hook for the driver wrapper in the base connection manager was added so that the file name could be resolved, lazily and in the background thread where the connection is being opened.
Lastly, if a bad path is used, a more proper error will be thrown instead of an obscure 'can't create file lock' since creating a file lock will first be attempted before actually creating / opening the actual database.
Bug: 377830104
Test: BuilderTest
Change-Id: I833154e2855a38520e5a0e8c802964bd455000e8
Files:
- M
room/integration-tests/multiplatformtestapp/src/androidInstrumentedTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BuilderTest.kt
- M
room/room-runtime/src/androidMain/kotlin/androidx/room/RoomConnectionManager.android.kt
- M
room/room-runtime/src/commonMain/kotlin/androidx/room/RoomConnectionManager.kt
- M
room/room-runtime/src/commonMain/kotlin/androidx/room/concurrent/ExclusiveLock.kt
Hash: 35ddf21c6ede1af577d2d20b96107e04988b04e0
Date: Fri Jan 17 15:42:06 2025
da...@google.com <da...@google.com>
na...@google.com <na...@google.com> #3
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.room:room-runtime:2.7.0-alpha13
androidx.room:room-runtime-android:2.7.0-alpha13
androidx.room:room-runtime-iosarm64:2.7.0-alpha13
androidx.room:room-runtime-iossimulatorarm64:2.7.0-alpha13
androidx.room:room-runtime-iosx64:2.7.0-alpha13
androidx.room:room-runtime-jvm:2.7.0-alpha13
androidx.room:room-runtime-linuxarm64:2.7.0-alpha13
androidx.room:room-runtime-linuxx64:2.7.0-alpha13
androidx.room:room-runtime-macosarm64:2.7.0-alpha13
androidx.room:room-runtime-macosx64:2.7.0-alpha13
Description
Component used: room
Version used: 2.7.0-alpha11
Devices/Android versions reproduced on: Android 11
I was porting our code over to the new AndroidSQLiteDriver. We previously pass in a database name of "data.db", like so:
Room.databaseBuilder(context, AppDatabase::class.java, "data.db")
With the new AndroidSQLiteDriver, it appears it requires an absolute path for the file. It doesn't give a clear error message about this however - it just says something about a read-only filesystem, (presumably it's resolving the filename against a read-only folder, instead of my app's database folder). Can you handle this case to give a clearer error message?
I was able to fix by using an absolute path like below, but it wasn't very easy to work out the problem.
Room.databaseBuilder(context, AppDatabase::class.java, context.getDatabasePath("data.db").absolutePath)