Skip to content
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

Unity 6 iOS | Unable to load dynamic library '/realm-wrappers' #3693

Open
samclothier opened this issue Jan 28, 2025 · 2 comments · May be fixed by #3694
Open

Unity 6 iOS | Unable to load dynamic library '/realm-wrappers' #3693

samclothier opened this issue Jan 28, 2025 · 2 comments · May be fixed by #3694

Comments

@samclothier
Copy link

samclothier commented Jan 28, 2025

What happened?

We have been having the following error in our iOS builds when building from a Unity project with Realm.NET 10.19 after updating from Unity 2021.3.42f1 to Unity 6. (see stack trace) It builds successfully in Xcode but has this error in the console when the game is run on an iOS device.

Realm runs perfectly on the Windows, Mac, and Linux builds from this project.

I first checked Xcode for problems with embedding and linking the realm-wrappers.framework, but it is included in the final archive:

Image

Notably, this is different from the Frameworks folder we had in the archive before Unity 6:

Image
The .meta files used to be present and the realm-wrappers file was automatically detected as UNIX executable. Now with Unity 6 it would have to be made executable with chmod +x realm-wrappers, but doing this before Xcode starts archiving results in the same error in the build above.

The output directly from Unity (before Xcode touches it) looks similar. Before Unity 6:

Image

And after:

Image

Additionally, under Library > PackageCache > io.realm.unity, the meta files appear to be present and the realm-wrappers is not an executable:

Image

Inside Unity itself (before any build export has taken place) we noticed that the iOS realm-wrappers file was the only one that didn't have its platform ticked, although this also appeared to be the case in Unity 2021.3.42f1:

Image

The equivalent on Android, for example, looks like this:

Image

We don't know if the difference in the Frameworks folder is the actual issue or if it's just a symptom of a problem elsewhere.

We have tried deleting the package cache, reinstalling Realm into the project, and clearing the Library folder between builds. We have also tried updating Realm to the latest version but that caused other issues.

Note: using IL2CPP and .NET Standard 2.1

Repro steps

Using Realm.NET 10.19, currently trying to build an empty Unity 6 project with a debug window, ran directly from Xcode on a tethered device. It's proving very difficult to test.

Version

10.19

What Atlas Services are you using?

Local Database only

What type of application is this?

Unity

Client OS and version

iOS all versions

Code snippets

No response

Stacktrace of the exception/crash you're getting

DllNotFoundException: Unable to load DLL 'realm-wrappers'. Tried the load the following dynamic libraries: Unable to load dynamic library '/realm-wrappers' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen(/realm-wrappers, 0x0005): tried: '/realm-wrappers' (no such file), '/private/preboot/Cryptexes/OS/realm-wrappers' (no such file), '/realm-wrappers' (no such file)
Realms.SharedRealmHandle+NativeMethods.open (Realms.Native.Configuration configuration, Realms.Native.SchemaObject[] objects, System.Int32 objects_length, Realms.Native.SchemaProperty[] properties, System.Byte[] encryptionKey, Realms.NativeException& ex) (at <00000000000000000000000000000000>:0)
Realms.SharedRealmHandle.Open (Realms.Native.Configuration configuration, Realms.Schema.RealmSchema schema, System.Byte[] encryptionKey) (at <00000000000000000000000000000000>:0)
Realms.RealmConfiguration.CreateHandle (Realms.Schema.RealmSchema schema) (at <00000000000000000000000000000000>:0)
Realms.RealmConfigurationBase.CreateRealm () (at <00000000000000000000000000000000>:0)
RealmManager.InitialiseRealm () (at <00000000000000000000000000000000>:0)
RealmManager+<InitialiseServiceAsync>d__28.MoveNext () (at <00000000000000000000000000000000>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <00000000000000000000000000000000>:0)

Relevant log output

@samclothier samclothier changed the title Unable to load dynamic library '/realm-wrappers' Unity 6 iOS | Unable to load dynamic library '/realm-wrappers' Jan 28, 2025
@nirinchev
Copy link
Member

So for previous Unity versions we needed to add a hacky workaround for the lack of support for xcframeworks. Unity 6 seems to add .xcframework support, which is why I'm guessing this is now broken and not behaving as intended. Since the Realm SDKs are now community supported, my suggestion would be to try and fix the issue and submit a PR (I'd be happy to review and provide feedback). To make it easier to iterate, it's probably best to first update to Realm 20.1.0 as that is the community version that doesn't include Atlas Device Sync, so it's a bit simpler. Then, you'd want to unarchive the io.realm.unity-20.1.0.tgz and import it as a filesystem package. Then, delete the Editor/Realm.UnityWeaver.dll file and replace it with the source code from the Realm.UnityWeaver + Realm.Weaver folders. Then, you can edit UnityWeaver.cs and check the Unity version and avoid applying the workaround in case it's Unity 6+.

@samclothier
Copy link
Author

So for previous Unity versions we needed to add a hacky workaround for the lack of support for xcframeworks. Unity 6 seems to add .xcframework support, which is why I'm guessing this is now broken and not behaving as intended. Since the Realm SDKs are now community supported, my suggestion would be to try and fix the issue and submit a PR (I'd be happy to review and provide feedback). To make it easier to iterate, it's probably best to first update to Realm 20.1.0 as that is the community version that doesn't include Atlas Device Sync, so it's a bit simpler. Then, you'd want to unarchive the io.realm.unity-20.1.0.tgz and import it as a filesystem package. Then, delete the Editor/Realm.UnityWeaver.dll file and replace it with the source code from the Realm.UnityWeaver + Realm.Weaver folders. Then, you can edit UnityWeaver.cs and check the Unity version and avoid applying the workaround in case it's Unity 6+.

Thanks very much for the quick reply.
To clarify, do you think doing as you described (update to 20.1 and avoid applying the workaround) would fix the error, or would this just get me into the position where the problem could be looked at? Unfortunately I'd have no idea where to start with changing this to work as an .xcframework or with how to prevent the workaround being applied. Was this just a .framework pre-Unity 6?

@samclothier samclothier linked a pull request Jan 29, 2025 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants