realm / realm-dart

Realm is a mobile database: a replacement for SQLite & ORMs.
Apache License 2.0
768 stars 87 forks source link

Using `realm-dart` alongside `RealmSwift` #1195

Open putnokiabel opened 1 year ago

putnokiabel commented 1 year ago

What happened?

We're working on a production Flutter app (on iOS) that's currently using RealmSwift, and we'd would like to migrate to using realm instead for the main app.

However, we need to be able to use both of these side-by-side, since we have native code supporting the home screen widgets and lock screen widgets on iPhone as well as our Apple Watch companion app (which currently also use RealmSwift).

It does not seem possible to compile an iOS app using both, as pod install throws the following exception: The 'Pods-Runner' target has frameworks with conflicting names: realm.

Is there a way to run both RealmSwift and realm-dart together?

Repro steps

  1. Create a fresh Flutter app supporting iOS (run flutter create -t app --platforms ios test).
  2. Run flutter add realm from the app directory to add the realm package.
  3. Add pod 'RealmSwift', '10.36.0' to ios/Podfile (or any other version of the pod for that matter).
  4. Run pod install from the ios folder.
  5. See the command fail with The 'Pods-Runner' target has frameworks with conflicting names: realm..

The issue persists regardless of the versions of realm or RealmSwift.

Version

1.0.2

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

iOS 16

Code snippets

No response

Stacktrace of the exception/crash you're getting

The 'Pods-Runner' target has frameworks with conflicting names: realm.

Relevant log output

No response

nielsenko commented 1 year ago

I must admit this was not a use-case we anticipated. I will investigate.

nielsenko commented 1 year ago

Apparently this should be possible, but right now the name clash prevents it. We will fix this in a coming release. Be aware that the different realm SDKs will still need to agree on the core file format version.

nielsenko commented 1 year ago

A few more caveats..

  1. If you are using sync, then only one SDK can do the syncing. With flutter you can open the realm with Configuration.disconnectedSync which will allow you to open a synchronized realm without starting a sync session. I don't think swift allows this, but as long as one of the SDKs does then it should be good.
  2. This relies on a feature of Mach-O where imported symbol are namespaced according to the shared object they come from - if they were using static linking then we’d be trying to cram two instances of Core in the same binary and they’d clobber each other.
  3. The realm library will essentially be loaded twice in your process.
putnokiabel commented 1 year ago

@nielsenko Thank you for the quick reply, that sounds great! The caveats you've mentioned should not be a problem for our use-case, we're not using sync and were already counting on the library being loaded twice to make this work.

putnokiabel commented 1 year ago

@nielsenko Are there any plans on how (and when) to address the naming conflict with RealmSwift?

nielsenko commented 1 year ago

@putnokiabel This did not make it into 1.1.0, I'm sorry

ghosharijit commented 1 year ago

@nielsenko , Thank you for the above update. any idea when can we expect the above change?

JYeop commented 1 year ago

Same usecase here. Maybe the podspec name should be changed. (ex: realm -> realm-flutter)

JYeop commented 1 year ago

Is there any plan to solve this issue?

nirinchev commented 1 year ago

Yes, we do intend to provide guidance on how to use Realm from multiple languages in the same app, but don't have timeframe for when that'll be available.

rjeprasad commented 1 year ago

@nielsenko This is a show-stopper for us. Please update ASAP. Any app with extension + realm will face this issue without a workaround. Just need a name change to remove the naming conflict. Rest should be fine for now.

nielsenko commented 1 year ago

@rjeprasad I'm sorry to hear that.

However, the original Dart team was laid of as part of a restructuring of Realm in September, and I no longer have any say in this, as I'm currently on garden leave.

I see my old colleague @nirinchev, who is the lead on the .NET SDK, and who was helping out on the Dart team previously, has already commented on the road map.

nirinchev commented 1 year ago

We have this scheduled for later this year.

ViolyCodevB commented 8 months ago

Is there any progress on this issue?

nielsenko commented 8 months ago

@ViolyCodevB We are waiting for https://github.com/flutter/flutter/issues/63240 to be resolved, or native-assets to land. It looks like the latter will happen first.

As is, we would have to have to rename the realm package, which is unlikely to happen for this corner-case.

nielsenko commented 8 months ago

I created a branch with the needed changes, but alas it won't work until https://github.com/flutter/flutter/issues/63240 is resolved.

ramzitannous commented 7 months ago

@nielsenko @nirinchev @rjeprasad is there any solution for this, I'm facing this issue exactly ?

sinhpn92 commented 3 months ago

Hello. Did this issue resolve? Or any suggest to solve? Thanks

nielsenko commented 3 months ago

@sinhpn92 Sorry, but no. I will make sure to update this issue if it happens. https://github.com/flutter/flutter/issues/63240 is still not resolved, native assets hasn't landed yet (still experimental), and we didn't rename the realm package in order to rename the pod either.

But put a 👍 on the. original issue, so we can monitor interest.