I want to use sdcard on Android to save and load Realm data.
The file can be created and loaded without problems using app's folder on external storage.
Unfortunately, when running Realm.open, it throws an exception of "Read-only file system", even after giving runtime permission to read and write external storage. I can see the file was created at the specified path.

It's an old issue that still not fixed. Please also see: #1760
Use below code sample
I open my database like this in react-native:
componentWillMount() {
Realm.open({
schema: [ Constant.BookSchema ],
path: '/storage/sdcard0/BookDB/db.realm'
}).then(realm => {
// some code here
});
}
I also add this two line to my AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
It's create below files in this location /storage/sdcard0/BookDB:
db.realm.managment
access_control.control.mx
access_control.write.mx
db.realm
db.realm.lock
But It's return red error page with Read-only file system error. (something like above image)
My device just have internal storage with /storage/sdcard0 location and it's not have any external SD card. (with Android 5.1.1 OS)
* Realm JS SDK Version: 2.15.3
* Node or React Native: 0.55.4
* Client OS & Version: Android API 25, 27
* Which debugger for React Native: None
Also some people tell that it's buggy on react-native version and only works in java version.
I ended up creating a bridge with Realm Java to solve this issue.
REF: https://github.com/realm/realm-js/issues/1760#issuecomment-397769082
Moved on to Realm Java and created a bridge between RN and Android source code
REF: https://stackoverflow.com/questions/49932627/read-only-filesystem-error-when-storing-data-on-sdcard
So this issue need more test (maybe it's a bug) and docs and not resolved.
@ianzitow @kneth, @bmunkholm
Anyone here?
Why no body use path parameter?
@mnlbox From API 23 you need to ask the user for granting permissions: https://facebook.github.io/react-native/docs/permissionsandroid
@kneth But if it's a permission issue why It's create below files in this location /storage/sdcard0/BookDB: :thinking: :thinking:
db.realm.managment
access_control.control.mx
access_control.write.mx
db.realm
db.realm.lock
@kneth Any idea?
Anyone here?
@mnlbox No real good suggestions. Can you create a minimal app which reproduce the issue? It can help us understand what the cause is.
Same problem here. Any fixes?
@kneth I try to provide some minimal reproduce repo for test soon.
@kneth here is a small example: https://github.com/Finneah/testRealmOnReactNative
@Finneah Thank you very much for this. I can reproduce the error on my end as well. I'm looking into it.
A few observations:
Download folder works fine. Hinting at Realm trying to write something where it shouldn't.Download folder. This works fine, which indicates a problem more directly with RealmJS or ReactNative, but since Java and JS instantiate things slightly differently, I'm still investigating that.@cmelchior Thanks for your work. Any news?
Guys I'm still waiting for a fix after 6 month 馃槥
Any plan to fix this?
@cmelchior
@mnlbox I still haven't found the root cause for this.
However, I noticed that opening the Realm fails to create a number of files:
// Locally
./test.realm
./test.realm.lock
./test.realm.note
./test.realm.management/access_control.control.mx
./test.realm.management/access_control.new_commit.cv
./test.realm.management/access_control.pick_writer.cv
./test.realm.management/access_control.write.mx
// On device
./test.realm
./test.realm.lock
./test.realm.management/access_control.control.mx
./test.realm.management/access_control.write.mx
// On device missing files
./test.realm.note
./test.realm.management/access_control.new_commit.cv
./test.realm.management/access_control.pick_writer.cv
I guess the reason you see the [Error: Read-only file system] error is because of the missing files. But I haven't been able to determine yet why.
Not, it appears not to be possible to create files anywhere on the SDCard. I also tried the app external data dir: /sdcard/Android/data/com.test/files which also fails.
Suggested root cause from our Core team:
perhaps mutex emulation is enabled, while condition variable emulation is disabled. That sounds problematic.
But I cannot explain why a pure Android app works fine while the React Native app doesn't.
Fixed in #2235
A release will be made later today
Thanks @cmelchior.
Most helpful comment
Fixed in #2235
A release will be made later today