Search code examples
androidreact-nativerealmgenymotion

RealmDB - React Native - Unable to open a realm at path '.management'


In a react-native project running Android on Genymotion I had the app running. At one point I received an issue and uninstalled the app from the VM. Upon re-running the app I received an alert:

Unable to open a realm at path '.management'.
Please use a path where your app has read-write permissions. <unknown>
    index.js:100 loadModuleImplementation
    require.js:171 guardedLoadModule
    require.js:123
_require
    require.js:107 <unknown>
    Repeaters.js:6 loadModuleImplementation
    require.js:171 guardedLoadModule
    require.js:123
_require
    require.js:107 <unknown>
    NavigationRouter.js:12 loadModuleImplementation
    require.js:171 guardedLoadModule
    require.js:123
_require
    require.js:107 <unknown>
    RootContainer.js:5 loadModuleImplementation
    require.js:171 guardedLoadModule
    require.js:123
_require
    require.js:107 <unknown>
    index.android.js:8 loadModuleImplementation
    require.js:171 guardedLoadModule
    require.js:116
_require
    require.js:107 global code
    require-0.js:1

I've tried shutting off Genymotion, uninstalling via adb shell, setting permissions manually via adb shell. I can't seem to fix the problem.

Any suggestions?

Thanks!


Solution

  • I was having the same problem because of the migrations. In ios worked fine but in android didn't.

    Code before

    let nextSchemaIndex = Realm.schemaVersion(Realm.defaultPath);
    while (nextSchemaIndex < schemas.length) {
      const migratedRealm = new Realm(schemas[nextSchemaIndex]);
      nextSchemaIndex += 1;
      migratedRealm.close();
    }
    

    Code now

    let nextSchemaIndex = Realm.schemaVersion(Realm.defaultPath);
    while (nextSchemaIndex < schemas.length) {
      const migratedRealm = new Realm({ ...schemas[nextSchemaIndex] });
      nextSchemaIndex += 1;
      migratedRealm.close();
    }
    

    Creating a new object for the Realm constructor solve the issue.

    Hopes it's helps.

    I didn't set a path for the schema but maybe this helps also.