Loading dylib from framework

I am very confused about the system with Unity on iOS. I have a dynamic library which I compiled for iOS. I know the library works as I have managed to start my game with it as a raw .dylib.

Unfortunately, dylib are not allowed in the app store so I need to encapsulate it inside a .framework - which I believe I did. But now when I launch the game, Unity is unable to initialize UnityFramework because it is unable to find that library. The path that are searched doesn’t seem to include the directory in which the framewok is.

My knowledge of Xcode is fairly limited. And there is no documentation from Unity on how to make framework works with IL2CPP code.

If anyone has any idea, that would be more than welcomed.

ps: I am trying to make System.Data.SQLite and SQLite.Interop work on iOS if that is relevant.

Have you tried putting that .dylib as plugin to Unity project and marking it compatible with iOS?

I tried to add the dylib to UnityFramework directly in xcode (since Unity 2022.3 has a bug where dylib are not copied) but it fails the same way. the dlopen call from UnityFramework is unable to locate the dylib.

But this has given me a few more ideas to try!

So I managed to solve the issue with the following steps:

  • Switched to Unity 6 (don’t know if that was necessary)
  • changed all DLL calls in System.Data.SQLite to __Internal
  • used install_name_tool to redefine the path to the library:
    install_name_tool -id @rpath/$frameworkname.framework/$frameworkname $frameworkname.framework/$frameworkname