realm / realm-js

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

735 duplicate symbols for architecture x86_64 when using RealmJS with RealmSwift #3588

Closed EricWiener closed 3 years ago

EricWiener commented 3 years ago

Goals

I have been successfully using RealmSwift with RealmJS. I just upgraded to RealmJS and RealmSwift 10 and I am now getting duplicate definition errors.

Expected Results

I expected to be able to use RealmSwift and RealmJS together without errors.

Actual Results

735 duplicate symbols for architecture x86_64

Sample of output:

duplicate symbol 'realm::_impl::TransactLogParser::parser_error() const' in:
    /Users/ericwiener/repositories/avoc/node_modules/realm/vendor/realm-ios/librealm-sync-ios.a(transact_log.o)
    /Users/ericwiener/Library/Developer/Xcode/DerivedData/Avoc-dquwvaaenvelplfebdxfllgbnecd/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/realm-monorepo/librealm-monorepo.a(transact_log.o)
duplicate symbol 'realm::_impl::TransactLogConvenientEncoder::~TransactLogConvenientEncoder()' in:
    /Users/ericwiener/repositories/avoc/node_modules/realm/vendor/realm-ios/librealm-sync-ios.a(transact_log.o)
    /Users/ericwiener/Library/Developer/Xcode/DerivedData/Avoc-dquwvaaenvelplfebdxfllgbnecd/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/realm-monorepo/librealm-monorepo.a(transact_log.o)
...

Steps to Reproduce

Use RealmSwift and RealmJS in the same project.

Podfile:

config = use_native_modules!

use_react_native!(:path => config["reactNativePath"])
# ...
Realm (from RealmSwift): 10.5.1
RealmSwift: 10.5.1
# ...

package.json:

 "react": "16.13.1",
 "react-native": "^0.63.2",
"realm": "10.2.0",

Code Sample

Unfortunately can't make this open-source, but I can provide it privately.

I made a new project with just the dependencies installed to try to get it to compile here. Unfortunately, RealmSwift doesn't compile due to the error:

Undefined symbols for architecture x86_64:
  "protocol descriptor for Swift.Identifiable", referenced from:
      protocol requirements base descriptor for RealmSwift.ObjectKeyIdentifiable in libRealmSwift.a(Combine.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

so I will be making a separate issue for RealmSwift.

Version of Realm and Tooling

steffenagger commented 3 years ago

Hello @EricWiener thanks for reporting.

When using RealmSwift with RealmJS, I believe this most important thing is to ensure the versions of Core & Sync matches on the different packages. It seems RealmJS is a bit behind. Could you try with RealmSwift@10.4.0, and let me know if you're sill seeing the errors?

EricWiener commented 3 years ago

Thank you so much! That fixed the issue:

I needed to change the Podfile to be:

pod 'RealmSwift', '10.4.0', :modular_headers => true
pod 'Realm', :modular_headers => true

And then I needed to do:

cd ios/
rm Podfile.lock
pod install

I also needed to clean my XCode build folder (through XCode) and derived data rm -rf ~/Library/Developer/Xcode/DerivedData.

In the future, how can I find out what version of RealmJS + RealmSwift I can use together?

steffenagger commented 3 years ago

In the future, how can I find out what version of RealmJS + RealmSwift I can use together?

There's no really elegant way (atm. at least), only comparing the changelogs: JS & Cocoa (under Internal, you'll find information about potential updates to Core/Sync, for the given version).

So a bit more cumbersome/manual I'm afraid.

EricWiener commented 3 years ago

Got it. Thanks so much for the help!