-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failure to open a Realm file on Android 14 #7037
Comments
So, which path is used for realm? How it was requested from the platform api? Did the open worked under the same path with android <= 13? |
@peppy does this reproduce for you on an emulator or only a physical device? I've tried setting up an emulator and opening a Realm and this works just fine, but it's possible there's something about the way Osu! does it that is different. If this only reproduces on a physical device, it'll be a bit of a bummer as we'll need to find one with Android 14. |
I don't actually have a device which is capable of android 14, and this was reported by a user. I've requested further details and will loop back. |
I can also reproduce on a physical Pixel 7 Pro running android 14 (this is my own kotlin-based android app):
If you need any extra information I would be glad to help |
We don't have the actual file path here (we should add this to our exception message) but it could be an android security limitation when using external storage as mentioned here #6028 (comment) |
Most likely it's still the same issues as #6912, just triggered later now since the realm-core v13.20.1 underneath contains fix #6926 @TymanWasTaken Starting with realm-core v13.20.1 you shouldn't see this assertion, but rather an exception for unlock. Could you tell which path and partition from android are used for realm? |
By the way, I just tested on both In addition, for some odd reason when my phone is running KernelSU, this error magically never happens. My app launches fine, and nothing gets shown in the logcat. However, when I re-flash my phone's stock boot image rather than the modified one, it starts happening again. I have no clue why that happens, and I'm not sure it's helpful at all, but it confused me for a minute because the error randomly stopped happening. To answer your question however, |
Hi @TymanWasTaken External Storage does not work with Realm from Android 11 due to the way Google implemented scoped storage: https://developer.android.com/about/versions/11/privacy/storage After this change, they only allow opening files on external storage using dedicated APIs that are incompatible with Realm. I'm not familiar with KernelSU, but most likely it is either based on an older version of Android or these security settings are disabled there. This unfortunately means that using Realm past Android 10 requires that the Realm is stored in the app's internal files directory You can still use the external storage, but only for backups of the file, not for normal use. You can also read more here: #6028 (comment) |
I can reproduce the same issue as @TymanWasTaken on a Google Pixel 6 running Android 14, using @cmelchior My app has been working fine on Android 11, 12, and 13. It only started failing on Android 14. Did something else change with scoped storage on Android 14? Otherwise, I can't see how the scoped storage changes introduced in Android 11 can be the cause since my app worked in Android 11, 12, and 13. |
There seems to be a misconception that Realm has not worked with external storage since Android 11 due to scoped storage. While true that Realm won't work at arbitrary locations in external storage, the app-specific directory on external storage is compatible with scoped storage and has worked for Realm in Android 11, 12, and 13. Realm is part of the app and has access to the app-specific directory. The app-specific directory on external storage can be retrieved using the getExternalFilesDir() method of the application context. For the hello-jni sample app in the NDK (with minor modification) it returns "/storage/emulated/0/Android/data/com.example.hellojni/files" on my Pixel 6 device. The getExternalStorageDirectory() method of the Environment object is easily confused with the getExternalFilesDir() method of the application context but is not the same thing. It provides the primary external shared directory, not the application-specific external directory. On the same Pixel 6 device it returns "/storage/emulated/0". So, while a realm in a subdirectory of getExternalFilesDir() should work, a realm in a subdirectory of getExternalStorageDirectory() only works to the extent the user has manually added the "Android/data/com.example.hellojni/files" path elements. The problem of using Realm in application-specific external storage is new to Android 14 and related to flock() no longer working. There is an issue in for this with Android https://issuetracker.google.com/issues/304123373. I'd suggest all facing this problem upvote the issue. |
I can reproducible this issue in backtrace: |
It seems this issue has been resolved in the November security update, at least on the Google Pixels. |
The same problem occurs with( I was wondering if I should put the database into internal storage ( |
Reported in realm/realm-dotnet#3458, looks like we have an issue when using flock on Android 14:
The text was updated successfully, but these errors were encountered: