realm-js: Missing Realm constructor. Did you run "react-native link realm"? Please(...)

Goals

Build under Ubuntu, on Android emulator, simple react-native project, which imports realm

Expected Results

Application runs without problems

Actual Results

Emulator(red screen of death): Missing Realm constructor. Did you run “react-native link realm”? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting

Console: Missing Realm constructor. Did you run “react-native link realm”? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting Module AppRegistry is not a registered callable module (calling runApplication)

Steps to Reproduce

Install Ubuntu 17.04/ get RN up and running/ using Webstorm create new RN project/ add import realm from 'realm' line to your code/ run react-native link realm and check that everything is linked properly/try building

Code Sample

MainApplication.java

import io.realm.react.RealmReactPackage;
...
@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RealmReactPackage()
      );
    }
...

settings.gradle

...
include ':realm'
project(':realm').projectDir` = new File(rootProject.projectDir, '../node_modules/realm/android')
...
build.gradle
...
dependencies {
    compile project(':realm')
...

Version of Realm and Tooling

  • Realm JS SDK Version: 1.13.0
  • Node: 6.11.2
  • React Native: 0.49.3
  • Client OS & Version: Ubuntu 17.04
  • React: 16.0.0-beta.5
  • Web Storm: 2017.2.2

Remarks

Other module, specifically SplashScreenReactPackage which also needs adding package to getPackages() in MainApplication.java works correctly.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 33 (7 by maintainers)

Most upvoted comments

I had the same problem today. I managed to get it working by:

  1. deleting ios and android folder
  2. recreating them with react-native eject
  3. link dependencies again with react-native link

Are you using wix/react-native-navigation? If you are there will be 2 getPackages() methods in your MainApplication.java, do make sure both methods are returning new RealmReactPackage().

Use this

npm install realm@hermes

Work’s for me.

from above 0.60 react native projects, auto link is not working either maintainers of the package has to code for auto linking project while doing npm install <package-name> itself. for make it work needs to manual link try drag and drop node module iOS project and add libRealmReact.a file to build phases. hope this will work

  1. try to delete the application from the device
  2. run react-native run-android again you will be ok