realm / realm-js

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

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

Closed zdzichukowalski closed 6 years ago

zdzichukowalski commented 6 years ago

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

Remarks

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

damir-sirola commented 6 years ago

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
zdzichukowalski commented 6 years ago

Well, it didn't help in my case, everything stays the same.

Is there any explanation behind your solution, or was it random idea that did work? I'm fairly new to RN, and would like to know if deleting native folders is common solution to unexpected situations.

damir-sirola commented 6 years ago

I suspected that the problem could be in .xcodeproj file. One of the biggest pains for me using RN is solving merge conflicts in .xcodeproj file, and we get quite a few of those on new projects.

kosiakMD commented 6 years ago

Had the same today on RN 0.47 & iOS 10.3 iPhone 6 for a few times before restarting app/server/build

kneth commented 6 years ago

Since we release 2.0 last week, I would like to hear if you see the error with that version?

michelalbers commented 6 years ago

Yes the error still persists with 2.0. It worked for a while and now the error reappears :(

Edit: Only happens when remote js debugging is turned on!

michelalbers commented 6 years ago

Created #1436 which fixes the issue for me! @kneth please have a look :)

tvhieuit commented 6 years ago

I'm still meet this issue. How to fix it :(

kneth commented 6 years ago

We plan to do a release early next week where the fix (#1436) is included.

sabbyt54 commented 6 years ago

+1 Can run on ios but not android

kneth commented 6 years ago

@sabbyt54 Which version of Realm JS are you using?

gusterwoei-veltra commented 6 years ago

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().

rahulbhankar786 commented 6 years ago

@kneth "realm": "^2.2.10" "react": "16.2.0", "react-native": "0.52.2",

jarodhanko commented 6 years ago

In case it helps anyone, I had this issue as well when running an Expokit project, until I disabled Live Reload.

kneth commented 6 years ago

@jarodhanko Expo does not yet support Realm.

jarodhanko commented 6 years ago

@kneth I ejected from Expo to use ExpoKit which allows the use of react-native link, which worked for my use-case (react native queue).

kneth commented 6 years ago

@jarodhanko Thanks for the update. It might be useful to others so maybe you can write a small post about it? For example at medium.com?

isaaclem commented 5 years ago

Is there any plan to support Expo?

georak commented 5 years ago

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

gauravgrover95 commented 5 years ago

reinstalling the app worked for me. This should be explicitly mentioned in the documentation. Any concerned person, please have a look or redirect me to the steps to fix it.

pedrosimao commented 5 years ago

I am facing the exact same issue. I am using ExpoKit 27.0.1, Realm 2.14.2, Redux and Redux-Thunk. I am running Realm operations from inside a Redux Action. I have tried everything described in the documentation and also what other users shared. Nothing really works for me. I am almost abandoning Realm because of this. Not sure if I should try to downgrade libraries versions....

kneth commented 5 years ago

@pedrosimao As mentioned in our documentation, Expo doesn't support Realm.

pedrosimao commented 5 years ago

@kneth got it!

coderscode2 commented 5 years ago

it worked for me when I added the following line to MainApplication.java protected List getPackages() { return Arrays.asList( new MainReactPackage(), new RealmReactPackage() // add this line ); }

Note: don't forget to import io.realm.react.RealmReactPackage;

pedrosimao commented 5 years ago

I ejected CRNA and the error disappeared.

alishgiri commented 5 years ago

As for me, Realm was working fine in Android but was throwing the above-mentioned error in iOS. Simple fix that I did was opened my project in xcode, AppDelegate.m file had error message poping up in the following line of code,

#import <React/RCTBundleURLProvider.h>

to fix it I went to Product > Schema > Manage Schema and then added React to the list.

sourabh2k15 commented 4 years ago

in my case I was not doing a "react-native run-android" after including realm code

tonynguyenit18 commented 4 years ago

In my case, It happened on IOS because I deleted libRealmreact.a file away from Link Binary with libraries. Make sure you have linReaclReact.a in Xcode => build phases => link binary with libraries

vinaynandyala commented 4 years ago

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 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

kkusanagi commented 4 years ago

starting from 0.61 react native ios project, realm cannot support anymore, as react native had remove its react project from ios library.

softmastx commented 4 years ago

starting from 0.61 react native ios project, realm cannot support anymore, as react native had remove its react project from ios library.

You mean that "We cannot use Realm for React Native version 0.61? Accoring to the lastest installation guide, we still can install with React Native >0.60 https://realm.io/docs/javascript/latest/

Mine, "react": "16.9.0", "react-native": "0.61.5", "realm": "^4.0.0-beta.0"

And still have an issue Unable to open a realm at path: Unsupported Realm file format

Any suggestion please help. Thanks

kneth commented 4 years ago

@softmastx Your error message ( Unable to open a realm at path: Unsupported Realm file format) indicates the Realm JS is loaded in your app. But it seems what you believe is a Realm file, isn't a Realm file.

Since you are using v4.0.0-beta.0, I would like to learn more. v4.0.0 will bring us a new file format, and old files will be automatically upgraded. If you are still observing the error, please create a new issue for it as it could indicate the file format upgrade has a bug.

WiharlleyWill commented 1 year ago

Use this

npm install realm@hermes

Work's for me.