realm-java: Cannot get Realm instance: io.realm.exceptions.RealmFileException: Unable to open a realm at path

Goal

Call Realm realm = Realm.getInstance(mRealmConfig); where

mRealmConfig = RealmConfiguration.Builder() .schemaVersion(2) .deleteRealmIfMigrationNeeded() .build();

Expected Results

Get a Realm without exception.

Actual Results

The following exception is thrown: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.dropbox.paper/files/default.realm.management': make_dir() failed: No such file or directory. (make_dir() failed: No such file or directory) (/data/data/com.dropbox.paper/files/default.realm.management) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 217 Kind: ACCESS_ERROR.

More here: realm-exception.txt

Steps & Code to Reproduce

This happens on first launch of the app.

Version of Realm and tooling

Realm version(s): 2.2.1

Tried upgrading to 3.1.2 but still seeing the same issue.

Realm sync feature enabled: unsure. Would this affect this? How can I turn this on/off?

Android Studio version: 2.3

Which Android version and device:

  • Nexus 5 on 6.0.1
  • Google Pixel 7.1.1

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 42 (22 by maintainers)

Most upvoted comments

FYI, simply calling Context.getFilesDir() before Realm.getInstance() also seems to fix the issue. Does the Realm native code call Context.getFilesDir()? Or does it assume the path is there and try to make a directory within it?

The service does not have android:isolatedProcess. Also we’re not initializing Realm on that service’s process.

We do the following in our custom Application class onCreate() method:

if ((new ProcessInfo(this)).findNameForCurrentProcess().endsWith(":crashes")) {
            return;
}

...

Realm.init(this);