realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.78k stars 575 forks source link

[react-native] read-only file system with realm #2442

Closed smarqito closed 4 years ago

smarqito commented 5 years ago

Goals

Realm working in Android 5.1.1

Expected Results

Not understanding why realm returns read-only file system

Actual Results

Currently my app is running smoothly with realm in the emulator and in Samsung S9+. Now I'm testing it in an older device with android 5.1.1 and I can't use Realm.

I found this issue #1760 but it doesn't answer it. I'm using default path (/data/data/com.myapp/files/REALM FILES)

ERROR: ` Read-only file system

[native code] loadModuleImplementation D:\3bcMobile\node_modules\metro\src\lib\polyfills\require.js:331:6 D:\3bcMobile\node_modules\react-redux\lib\connect\wrapMapToProps.js:62:41 loadModuleImplementation D:\3bcMobile\node_modules\metro\src\lib\polyfills\require.js:331:6 D:\3bcMobile\node_modules\react-native\Libraries\Renderer\oss\ReactFabric-prod.js:6999:28 loadModuleImplementation D:\3bcMobile\node_modules\metro\src\lib\polyfills\require.js:331:6 D:\3bcMobile\index.js:6 loadModuleImplementation D:\3bcMobile\node_modules\metro\src\lib\polyfills\require.js:331:6 guardedLoadModule D:\3bcMobile\node_modules\metro\src\lib\polyfills\require.js:197:45 global code ` ## Steps to Reproduce `git clone https://github.com/smarqito/3bcMobile react-native run-android` <-- all you need to reproduce ## Code Sample **my realm.js where I export the schemas:** ` "use strict"; import Realm from 'realm'; class ProductsSchema extends Realm.Object {} ProductsSchema.schema = { name: 'Product', properties: { art_ref: {type: 'string', indexed: true}, art_dcr: 'string', stk_vis: 'int', art_ven: 'int', last_update: 'date' } }; class CbaSchema extends Realm.Object {} CbaSchema.schema = { name: 'CBA', properties: { art_ref: 'string', art_cba: 'string' } }; class DatabaseSchema extends Realm.Object {} DatabaseSchema.schema = { name: 'Database', properties: { storeName: 'string', username: 'string', password: 'string', host: 'string', port: 'int', hasSync: 'bool', last_update: 'date' } } class UserDataSchema extends Realm.Object {} UserDataSchema.schema = { name: 'UserData', properties: { user: 'string', password: 'string', userToken: 'string', last_update: 'date' } } export default new Realm( {schema: [ProductsSchema, CbaSchema, DatabaseSchema, UserDataSchema] }) ` **package.json:** ` { "name": "my3bc", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "@react-native-community/netinfo": "^3.2.1", "react": "16.8.3", "react-native": "0.59.9", "react-native-bcrypt": "^2.4.0", "react-native-fingerprint-scanner": "^2.6.1", "react-native-gesture-handler": "^1.3.0", "react-native-mssql": "^0.1.2", "react-native-touch-id": "^4.4.1", "react-native-vector-icons": "^6.6.0", "react-navigation": "^3.11.0", "react-redux": "^7.1.0", "realm": "^3.0.0-beta.1", "redux": "^4.0.1", "redux-thunk": "^2.3.0", "tachyons-react-native": "^1.0.1" }, "devDependencies": { "@babel/core": "7.4.5", "@babel/runtime": "7.4.5", "babel-jest": "24.8.0", "jest": "24.8.0", "metro-react-native-babel-preset": "0.54.1", "react-test-renderer": "16.8.3" }, "jest": { "preset": "react-native" } } ` ## Version of Realm and Tooling - Node or React Native: React Native - Client OS & Version: Android 5.1.1 - Which debugger for React Native: ?/None
kneth commented 5 years ago

https://github.com/smarqito/3bcMobile doesn't exist (or maybe it's a private repo).

1760 is about external storage, and it seems like you are not using that, right?

Can you create plain files in /data/data/com.myapp/files? Can post paste the relevant section of the Android log (adb logcat), please.

smarqito commented 5 years ago

https://github.com/smarqito/3bcMobile doesn't exist (or maybe it's a private repo).

1760 is about external storage, and it seems like you are not using that, right?

Can you create plain files in /data/data/com.myapp/files? Can post paste the relevant section of the Android log (adb logcat), please.

Well it's a private repo, I've just shared the repo with you (it has some private info I don't want to be public). Please use the master branch. In the second branch I'm working with sqlite (since I'm stuck with realm).

1760 it's about external storage and it isn't my case, exactly. I'm using default path for realm.

I've tested the app with <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> just in case but it doesn't work anyway.

The app is creating the files in /data/data/com.myapp/files: ReactNativeDevBundle.js default.realm default.realm.lock default.realm.management Manually, I created through adb shell -> run-as com.myApp -> touch test.js and it created the file, no errors

Please find the log from the moment previous to the realm loading: E/Vold ( 257): Failed to find mounted volume for /storage/sdcard1/Android/data/com.my3bc/cache/ I/Adreno-EGL(20682): <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8916_32_LA.BR.1.2.4_RB1__release_AU (Ibddc658e36) I/Adreno-EGL(20682): OpenGL ES Shader Compiler Version: E031.25.03.04 I/Adreno-EGL(20682): Build Date: 09/08/15 Tue I/Adreno-EGL(20682): Local Branch: mybranch13903027 I/Adreno-EGL(20682): Remote Branch: quic/LA.BR.1.2.4_rb1.17 I/Adreno-EGL(20682): Local Patches: NONE I/Adreno-EGL(20682): Reconstruct Branch: NOTHING **W/ContextImpl(20682): Failed to ensure directory: /storage/sdcard1/Android/data/com.my3bc/cache** I/OpenGLRenderer(20682): Initialized EGL, version 1.4 **D/SoLoader(20682): About to load: librealmreact.so D/SoLoader(20682): librealmreact.so not found on /data/data/com.my3bc/lib-main D/SoLoader(20682): librealmreact.so found on /data/app/com.my3bc-2/lib/arm D/SoLoader(20682): Not resolving dependencies for librealmreact.so D/OpenGLRenderer(20682): Enabling debug mode 0 D/SoLoader(20682): Loaded: librealmreact.so V/JSRealm (20682): setDefaultRealmFileDirectory D/JSRealm (20682): Absolute path: /data/data/com.my3bc/files** D/ReactNative(20682): Initializing React Xplat Bridge. D/ReactNative(20682): Initializing React Xplat Bridge before initializeBridge D/ReactNative(20682): Initializing React Xplat Bridge after initializeBridge D/ReactNative(20682): CatalystInstanceImpl.runJSBundle() D/ReactNative(20682): ReactInstanceManager.setupReactContext() D/ReactNative(20682): CatalystInstanceImpl.initialize() D/ReactNative(20682): ReactInstanceManager.attachRootViewToInstance() W/unknown:ReactNative(20682): Packager connection already open, nooping. I/Timeline(20682): Timeline: Activity_idle id: android.os.BinderProxy@2a0492d9 time:11682212 I/ActivityManager( 1589): Displayed com.my3bc/.MainActivity: +632ms I/Timeline( 1589): Timeline: Activity_windows_visible id: ActivityRecord{3b7969c2 u0 com.my3bc/.MainActivity t747} time:11682215 D/ConnectivityService( 1589): onUidRulesChanged(uid=10024, uidRules=0) W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTGroupViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTGroupShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTShapeViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTShapeShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTTextViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTTextShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.checkbox.ReactCheckBoxManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.uimanager.LayoutShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.picker.ReactDialogPickerManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.drawer.ReactDrawerLayoutManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.picker.ReactDropdownPickerManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.scroll.ReactHorizontalScrollViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.scroll.ReactHorizontalScrollContainerViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.progressbar.ReactProgressBarViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.progressbar.ProgressBarShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.scroll.ReactScrollViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.slider.ReactSliderManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.slider.ReactSliderManager$ReactSliderShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.switchview.ReactSwitchManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.switchview.ReactSwitchManager$ReactSwitchShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.toolbar.ReactToolbarManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.webview.ReactWebViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.swiperefresh.SwipeRefreshLayoutManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTSurfaceViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.art.ARTSurfaceViewShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.frescosupport.FrescoBasedReactTextInlineImageViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.frescosupport.FrescoBasedReactTextInlineImageShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.image.ReactImageManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.modal.ReactModalHostManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.modal.ModalHostShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.ReactRawTextManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.ReactRawTextShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.textinput.ReactTextInputManager I/SurfaceFlinger( 259): FPS: 45 W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.textinput.ReactTextInputShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.ReactTextViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.ReactTextShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.view.ReactViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.viewpager.ReactViewPagerManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.ReactVirtualTextViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.facebook.react.views.text.ReactVirtualTextShadowNode W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.swmansion.gesturehandler.react.RNGestureHandlerRootViewManager W/unknown:ViewManagerPropertyUpdater(20682): Could not find generated setter for class com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager D/SoLoader(20682): About to load: libyoga.so D/SoLoader(20682): libyoga.so not found on /data/data/com.my3bc/lib-main D/SoLoader(20682): libyoga.so found on /data/app/com.my3bc-2/lib/arm D/SoLoader(20682): Not resolving dependencies for libyoga.so D/SoLoader(20682): Loaded: libyoga.so D/SoLoader(20682): init exiting E/WifiStateMachine( 1589): WifiStateMachine CMD_START_SCAN source -2 txSuccessRate=1,41 rxSuccessRate=0,83 targetRoamBSSID=any RSSI=-61 I/WebViewFactory(20682): Loading com.android.webview version 39 (eng.john-arm) (code 399991) I/LibraryLoader(20682): Time to load native libraries: 3 ms (timestamps 3281-3284) I/LibraryLoader(20682): Expected native library version number "",actual native library version number "" W/art (20682): Attempt to remove local handle scope entry from IRT, ignoring I/SurfaceFlinger( 259): FPS: 4 W/mqt_js (20716): type=1400 audit(0.0:1374): avc: denied { create } for name="access_control.new_commit.cv" scontext=u:r:untrusted_app:s0 tcontext=u:object_r:xt_data_file:s0 tclass=fifo_file permissive=0 **E/ReactNativeJS(20682): Read-only file system E/ReactNativeJS(20682): Module AppRegistry is not a registered callable module (calling runApplication)** I/ViewRootImpl(20682): CPU Rendering VSync enable = true V/WindowManager( 1589): not Base app: Adding window Window{1b6fa117 u0 com.my3bc/com.my3bc.MainActivity} at 4 of 8 V/WLAN_PSA( 283): NL MSG, len[4089], NL type[0x1C] WNI type[0x5900] len[57615] V/WLAN_PSA( 283): NL MSG, PID: 283 V/WLAN_PSA( 283): NL MSG, len[048], NL type[0x11] WNI type[0x5050] len[028] V/WLAN_PSA( 283): NL MSG, PID: 283

Can this be due to Android 5.1.1 is SDK 22 and Realm pre-requisites are SDK 23+? Is there anyway to go around that?

If I go to build.gradle I find: `android { compileSdkVersion 28

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
}`

Thank you for your help. This has froze my app development.

smarqito commented 5 years ago

I've been reading the log a bit closer and found this: avc: denied { create } for name="access_control.new_commit.cv" scontext=u:r:untrusted_app:s0 tcontext=u:object_r:xt_data_file:s0 tclass=fifo_file permissive=0 And then it returns the error read-only file system. Can it be due to this?

kneth commented 5 years ago

Realm JS supports SDK 16 (and I think we can go even further back) so Android 5.1.1 should be fine.

The log entry as you mention is a SELinux violation, and I think it is the root of your issue. I have found https://stackoverflow.com/questions/44743797/selinux-android-message-intrepetion but it has no solution. As you can see, the issue is with a Realm file too.

Actually I think it is the same issue as https://github.com/realm/realm-java/issues/5790.

Which device are you testing on?

nhachicha commented 5 years ago

@smarqito Did you manage to reproduce the issue on a stock emulator with Android 5.1.1? this could be related to a custom ROM not defining the SELinux permission correctly ...

smarqito commented 5 years ago

@nhachicha I haven't tried until now and it seems to be working on the emulator with android 5.1.1. In the meanwhile I've tested SQLite and it works properly in the device that Realm bugs (no file error). Having this, what might realm.js (under react-native) be doing that returns that error and SQLite doesn't? Is there any way to fix the SELinux permission in the custom ROM of that device?

smarqito commented 5 years ago

@kneth the device I'm testing is an X64 PDA (with 2D barcode scanner)

nhachicha commented 5 years ago

what might realm.js (under react-native) be doing that returns that error and SQLite doesn't?

Realm internally creates some FIFO/pipe files (see https://github.com/realm/realm-js/issues/2442#issuecomment-510554415) to allow interprocess communication, similar to Realm-Java for instance, normally this shouldn't be a problem, but some custom ROM might have an SELinux configuration which prevents it.

You can try this which is opening the Realm in a different directory which might have the correct SELinux policies set which allows creating pipes ...

smarqito commented 5 years ago

@nhachicha Is there anyway to check if there is any directory where SELinux allows creating pipes?

Maybe only having the SELinux config file?

kneth commented 5 years ago

@smarqito It can be rather complicated to get the SELinux configuration as it consists of many components (see https://source.android.com/security/selinux/build).

smarqito commented 5 years ago

@kneth It took a while but I've already found the problem and how to solve it. The only issue is that I didn't manage to actually try it (not able to change SELinux configuration).

Once I've the feedback if the solution works I'll post here the steps I did to find the problem and the solution. In the meanwhile, for those who have the same problem, just do a simple test to verify if it's related to SEpolicy issue: root the device, and run: setenforce 0 <- this will set the SELinux to permissive mode: denials will only be logged, not enforced. If the app works this way, then it's a SEpolicy issue.

Thank you for your help.

kneth commented 5 years ago

@smarqito Thanks for the update.