Skip to content

Missing Realm constructor or duplicated symbols #2634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hauhuynh1208 opened this issue Dec 4, 2019 · 41 comments
Closed

Missing Realm constructor or duplicated symbols #2634

hauhuynh1208 opened this issue Dec 4, 2019 · 41 comments

Comments

@hauhuynh1208
Copy link

hauhuynh1208 commented Dec 4, 2019

Goals

Using Realm normally

Expected Results

Actual Results

after install Realm and pod install, app will launch with error Missing Realm constructor. After research through github, I found that we should link libRealmReact.a to Link binary with libraries. But after linked, app throw error that 155 duplicate symbols for architecture x86_64.

Steps to Reproduce

react-native init exampleProject
yarn add realm
cd ios && pod install

Code Sample

import Realm from 'realm

Version of Realm and Tooling

  • Realm JS SDK Version: 3.5.0
  • Node or React Native: node 10.15.3 RN 0.61.2
  • Client OS & Version: Mac OSX Catalina 10.15.1 Xcode 11.2.1
  • Which debugger for React Native: None
@hauhuynh1208
Copy link
Author

Confirm that only iOS platform experience this bug, Android still work properly.

@kneth
Copy link
Contributor

kneth commented Dec 4, 2019

I haven't been able to reproduce it. I am using Realm JS v3.5.0 and React Native v0.61.2 but on macOS v10.14.6 and Xcode 11.0 (build version 11A420a).

@gangwarily
Copy link

Running into this same issue on a pre-existing project that was previously using Realm JS v2.29.2. On macOS v10.4.6, RN v.0.61.2 and Xcode 11.2.1.

@hauhuynh1208
Copy link
Author

@kneth I created a new project and also added realm, it is working normally. However, my pre-existing project still throw error. I confirm that my pre-existing project used to run normally and I didn't update any packages. How can I share my pre-existing project (private project) so you can take a look?

@hauhuynh1208
Copy link
Author

hauhuynh1208 commented Dec 5, 2019

@gangwarily After I added all the packages from pre-existing project to the new one, my new project ran into the same issue as the existed project. Let's compare to see which packages we have the same

"@react-native-community/geolocation": "^2.0.2",
        "@react-native-community/netinfo": "^4.4.0",
        "events": "^3.0.0",
        "formatcoords": "^1.1.3",
        "geolib": "^3.0.4",
        "lodash": "^4.17.15",
        "moment": "^2.24.0",
        "native-base": "^2.13.8",
        "prop-types": "^15.7.2",
        "react": "16.9.0",
        "react-native": "0.61.5",
        "react-native-datepicker": "^1.7.2",
        "react-native-device-info": "^4.0.1",
        "react-native-geolocation-service": "^3.1.0",
        "react-native-gesture-handler": "^1.4.1",
        "react-native-image-picker": "^1.1.0",
        "react-native-location": "^2.5.0",
        "react-native-maps": "0.25.0",
        "react-native-modal": "^11.1.0",
        "react-native-reanimated": "^1.2.0",
        "react-native-screens": "^1.0.0-alpha.23",
        "react-native-share": "^2.0.0",
        "react-native-svg": "^9.11.1",
        "react-native-tab-view": "^2.9.0",
        "react-native-uuid": "^1.4.9",
        "react-native-vector-icons": "^6.6.0",
        "react-navigation": "^4.0.10",
        "react-navigation-drawer": "^2.2.2",
        "react-navigation-stack": "^1.9.4",
        "react-redux": "^7.1.0",
        "realm": "^3.5.0",
        "redux": "^4.0.4",
        "redux-thunk": "^2.3.0",
        "rn-fetch-blob": "^0.11.2",
        "victory-native": "^33.0.0"

@kneth
Copy link
Contributor

kneth commented Dec 5, 2019

@hauhuynh1208 You can send it to help--at--realm.io and mention that it is for me. Eventually I will get it 😄.

@hauhuynh1208
Copy link
Author

hauhuynh1208 commented Dec 5, 2019

@kneth I think I found the way how you can reproduce the bug. First of all, init the fresh project. Then install realm, make sure app is running properly. Then you install any packages (such as redux, react-native-maps ...). Then bug occurs

react-native init example
cd example/
yarn add realm
cd ios/ && pod install
cd ../
yarn add redux

I sure you will encounter this bug :)

@kneth
Copy link
Contributor

kneth commented Dec 6, 2019

@hauhuynh1208 I do encounter the bug.

We believe it is a yarn issue, and we are working on a solution (see #2623). When you do yarn add redux, the node_modules/realm folder is reset, and the header and binary files you need, are deleted!

Currently, two workarounds are possible: use npm instead of yarn or add the line "postinstall": "node node_modules/realm/scripts/download-realm.js ios --sync" to the scripts section in your package.json (see #2617 (comment)).

@gangwarily
Copy link

@kneth, I'm using npm and running into the same issue. Not sure if there are multiple causes for this :/

@hauhuynh1208
Copy link
Author

@kneth I have tried postinstall solution before, and it still fail. And I just tried npm, but still no luck. Did you do these solutions successfully?
P/s for my existed project, when I do postinstall ..., the error that xcode cannot find realm has been passed. But I continue to fall in the problem I described in this thread title.

@kraenhansen
Copy link
Member

What happens if you run pod install as the last step before react-native run-ios?

@esutton
Copy link

esutton commented Dec 6, 2019

@hauhuynh1208 Search your ios/YourProject.xcodeproj for "realm". Mine had dozens of realm entries.

I think this may be a problem when upgrading existing projects. Not sure how best to solve.

Option A
This is what I did.

  1. react-native unlink realm
  2. yarn remove realm
  3. Manually remove all the realm lines from ios/YourProject.xcodeproj
  4. yarn add realm

Option B
This might help understand what realm is trying to do. ( Not sure if it is correct or not )

  1. Create a new Awesome project and add realm
  2. Compare the new ios/Awesome.xcodeproj to your project and copy realm related lines

I ended up rolling back to "realm": "^3.2.0" and manually adding and linking the realm project in xcode.

I spent so much time on this trying so many things. I and not sure what finally sorted things out.

File: react-native.config.js

module.exports = {
  dependencies: {
    realm: {
      platforms: {
        ios: null, // disable iOS platform, other platforms will still autolink if provided
      },
    },
  },
};

I am sticking with realm 3.2.0 for now:

    "react": "^16.9.0",
    "react-native": "0.60.6",
    "realm": "3.2.0",
    "redux": "^4.0.4",

@kraenhansen
Copy link
Member

@esutton while I applaud your eager to find alternative solutions and I am happy you personally got your stuff working, it really doesn't need to be that difficult.. I believe the minority of Realm JS issues we're seeing on iOS stem from old files in ios/build, not running pod install or hacked up XCode projects.

If you create your own issue (with a link to your project on GitHub or a request for an email address to which you can send it privately), I'll be happy to take a look at what's wrong and help resolve any Realm related issues.

@esutton
Copy link

esutton commented Dec 6, 2019

@kraenhansen In tried rm -rf ios/build multiple times without success. Adding postinstall work-around did not help. I did not forget pod install

Yes, something appeared to mess up Xcode project. This occurred * before * I manually edited the xcode project. I am also using redux.

@hauhuynh1208
Copy link
Author

@kraenhansen In my existed project, I always remember to pod install every after I added yarn add realm. The pod install process is normal, installing Realm (3.5.0) and GCDWebServer (3.5.3).

@kneth
Copy link
Contributor

kneth commented Dec 9, 2019

@gangwarily Did you remove the contents of ios/build first?

@kneth
Copy link
Contributor

kneth commented Dec 9, 2019

@hauhuynh1208 @esutton You use try to use npm instead of yarn just to see if it makes a difference?

@hauhuynh1208
Copy link
Author

@kneth I tried npm. It throws error that Missing Realm constructor ...

@kneth
Copy link
Contributor

kneth commented Dec 10, 2019

@hauhuynh1208 Can you create a small project which can reproduce the issue and share it with us?

@gangwarily
Copy link

@gangwarily Did you remove the contents of ios/build first?

I did yeah. Pretty much tried all the things @hauhuynh1208 tried out. :/

@hauhuynh1208
Copy link
Author

@kneth here is my small git:
https://github.com/hauhuynh1208/example.git

I did the following steps:

  1. react-native init example
  2. yarn add realm
  3. cd ios/ && pod install && cd ../
  4. yarn add redux

@kneth
Copy link
Contributor

kneth commented Dec 11, 2019

@hauhuynh1208 As outlined earlier, the command yarn add redux will remove the binary files used by Realm. I don't see a postinstall script in package.json.

@hauhuynh1208
Copy link
Author

@kneth I followed your instruction, the example project is working normally. But I applied the same to my existed project, and the project still fail to build. How can I send you this existed project privately so that you can help me take a look?

@lntoan
Copy link

lntoan commented Dec 12, 2019

I got the same issues

@ruslanaplid
Copy link

ruslanaplid commented Dec 12, 2019

"react-native": "0.61.2",
"realm": "^3.5.0",

If run $ react-native run-ios - its ok

If run project in xCode to simmulator - Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting

If remove folder ios/build and again run project in xCode - again Error "Missing Realm constructor" and folder ios/build is empty

UPD: Go to xCode menu Product -> Clean Build Folder - Yesssss YO!
Its work

@hauhuynh1208
Copy link
Author

@ruslanaplid I even though cannot run project by react-native run-ios :((

@kraenhansen
Copy link
Member

@hauhuynh1208 we just released a version of Realm JS with a fix that could very well solve your issue too. I just ran the following without errors:

npx react-native init example
cd example/
yarn add realm
cd ios/ && pod install
cd ../
yarn add redux
yarn ios

Can you confirm that the latest version of Realm JS (v2.6.0) solves your issue?

@hauhuynh1208
Copy link
Author

@kraenhansen I confirm that my example project now work perfectly. But my existed project still fail. Btw, thank you very much for your help :D

@kraenhansen
Copy link
Member

kraenhansen commented Dec 13, 2019

@hauhuynh1208 my best suggestion is to initialize a new React Native project, copy over the dependencies from the package.json file, all your JavaScript code and any assets / resources that you might have added. It's the most effective way of unbreaking an XCode project in my experience.

I'm closing this issue for now, please open a new with a link for a GitHub repository with a minimal reproduction if you find a similar issue (or can distill your existing project somehow).

@realm realm deleted a comment from RealmBot Dec 13, 2019
@hauhuynh1208
Copy link
Author

hauhuynh1208 commented Dec 16, 2019

I found the solution:

  1. create a new project with the same name as your existed project
  2. removeios folder from existed project, and replace by the ios folder which is created from the new one.
  3. remove node_modules and yarn.lock/package-lock.json
  4. Add pod link if needed in Podfile
  5. Make sure your ios folder dont includes Pods/ and Podfile.lock
  6. yarn add realm
  7. cd ios/ && pod install && cd ../
  8. yarn start && yarn run ios

Hope my workaround could help who are got stuck on running existed project with realm :)

@Rotemy
Copy link

Rotemy commented Dec 17, 2019

"react-native": "0.61.2",
"realm": "^3.5.0",

If run $ react-native run-ios - its ok

If run project in xCode to simmulator - Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting

If remove folder ios/build and again run project in xCode - again Error "Missing Realm constructor" and folder ios/build is empty

UPD: Go to xCode menu Product -> Clean Build Folder - Yesssss YO!
Its work

I spent 2 hours on this, and this fixed my problem. Be sure to tap options to make Clean -> Clean Build Folder

@a396901990
Copy link

"react-native": "0.61.2",
"realm": "^3.5.0",
If run $ react-native run-ios - its ok
If run project in xCode to simmulator - Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
If remove folder ios/build and again run project in xCode - again Error "Missing Realm constructor" and folder ios/build is empty
UPD: Go to xCode menu Product -> Clean Build Folder - Yesssss YO!
Its work

I spent 2 hours on this, and this fixed my problem. Be sure to tap options to make Clean -> Clean Build Folder

i spend 2 hours too, and then I found your answer ...

@brien-crean
Copy link

"react-native": "0.61.2",
"realm": "^3.5.0",

If run $ react-native run-ios - its ok

If run project in xCode to simmulator - Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting

If remove folder ios/build and again run project in xCode - again Error "Missing Realm constructor" and folder ios/build is empty

UPD: Go to xCode menu Product -> Clean Build Folder - Yesssss YO!
Its work

One thing that wasn't obvious to me was to hold the option key while selecting the product menu to get the Clean Build Folder... option

Cleaning the build folder fixed it for me

@rashidul-hasan
Copy link

I'm facing the exact same cleaning build folder didn't work. any help? RN: 0.61.5, Realm: 3.2.0

@enigmablue
Copy link

Same problem :( Tried everything from cleaning build folder, to deintegrate pods, restarted everything.
Am trying to upgrade from RN 0.61.2 to 0.62 on Realm 3.6

@mrarronz
Copy link

I have this problem too, I upgrade Realm 3.2.0 to Realm 10.2.0 due to iOS 14.5 beta crash, but always encounter this missing Realm constructor issue, this really drive me to crazy, I have tried all the ways I could think of and read all the solutions above, still cannot resolve this. I'm really upset about this, this issue keeps showing up to developers but still cannot be resolved totally, I decide to remove this entirely from my project and never use it again!

@mklb
Copy link

mklb commented Feb 14, 2021

I have the same issue like @mrarronz -> upgrading from Realm 3.2.0 to the newest 10.2.0.
Cleaning the build folder, cleaning npm cache, reinstalling node modules and cocoa pods and running react-native link realm helped. It is weird that the auto linking still does not work.

@kneth
Copy link
Contributor

kneth commented Feb 15, 2021

@mrarronz @mklb Are you upgrading React Native and Realm at the same time?

@mrarronz
Copy link

mrarronz commented Feb 22, 2021

@kneth I upgrade React Native to 0.63 and Realm to v10.2.0, always encounter this issue. After struggling for two days, I finally resolve this issue. It takes a big effort to replace this library in my project so I have to keep it at this moment. Since the iOS 14.5 beta crash seems already be resolved in v6(#3557), so I just upgrade Realm to v6.1.6 instead of v10.2.0.

Here are my steps to fix this, hope it would be helpful to anyone who are facing this problem.

  1. rm -rf node_modules
  2. rm -rf ios/Pods
  3. yarn cache clean, steps 1-3 are not required due to my testing.
  4. change Realm version to 6.1.6 in package.json, then run yarn install
  5. cd ios && pod install && cd ..
  6. Build iOS project with Xcode or command react-native run-ios
  7. Observe that the "Missing Realm constructor" happens again on the simulator
  8. Add RealmReact.xcodeproj to the app project from the folder node_modules/realm/react-native/ios, add libRealmReact.a in the app target's build phase - link binary with libraries, build project again
  9. observe that the duplicated symbols error happens "155 duplicate symbols for architecture x86_64", remove the RealmJS.xcodeproj reference from RealmReact.xcodeproj, and rebuild on the simulator, this time it succeeds.
  10. Archive app product manually or run with fastlane, project still fails with duplicated symbols, because the RealmReact source files also exist in the Pods project RealmJS. This time remove RealmReact.xcodeproj reference totally from the project, the libRealmReact.a will be removed along with RealmReact.xcodeproj. Archive again, finally succeed.
  11. Try running the app on the simulator, still successful.

What a painful process! I finally resolve this after trying a lot, but I have no confidence that it would always run successfully on somewhere else.

@kneth
Copy link
Contributor

kneth commented Feb 22, 2021

@mrarronz Thank you for providing a detailed guide on how to upgrade.

@mklb
Copy link

mklb commented Feb 25, 2021

@mrarronz @mklb Are you upgrading React Native and Realm at the same time?

No I did not update React Native. However the last time I updated Realm I used an older version of React Native.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests