ericsink / SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite
Apache License 2.0
523 stars 109 forks source link

Unity Support, on M1 Mac (DllNotFoundException: e_sqlite3 assembly:<unknown assembly> type:<unknown type> member:(null)) #501

Closed ecsplendid closed 2 years ago

ecsplendid commented 2 years ago

Hey folks

I get this error. Unity is a pain. I want to use the sqlite library https://github.com/praeclarum/sqlite-net -- in our code I noticed that it was using the code from this library from 12 years ago, although now after all this pain I am starting to see why. We want to update to the latest version of the library because we're getting all sorts of threading crashes. Before it was presumably loading in the sqllite lib, installed on my main system. So I updated to the latest version of sqlite-net, and that was what led me to need to install this library.

I have used the "NuGet plugin" for Unity, installed a combination of packages until I could get it building --

image

Which is to say;

DllNotFoundException: e_sqlite3 assembly:<unknown assembly> type:<unknown type> member:(null)
SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number () (at <7158634a0cea490799582053c6fc6ea6>:0)
SQLitePCL.raw.SetProvider (SQLitePCL.ISQLite3Provider imp) (at <00c3759168224530a91b0fc2aa365b59>:0)
SQLitePCL.Batteries_V2.Init () (at <8af1e3e41bee433e83bc9d8d616eb39c>:0)
SQLite.SQLiteConnection..cctor () (at <01c96d411fe34bd5940c99a56515582b>:0)
Rethrow as TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception.
DataService..ctor (System.String DatabaseName) (at Assets/Scripts/DataHandler.cs:34)
Database..ctor () (at Assets/Scripts/Database.cs:7)
Logger..ctor (System.String tag_) (at Assets/Scripts/Logger.cs:10)
AudioProcessor.Awake () (at Assets/Scripts/AudioProcessor.cs:61)

When I look in the nuget folders which were downloaded, I don't see a .dylib which presumably my mac needs. The Unity nuget manager only downloads the .net standard 2 folder, if I download with another package manager, I can see such a file on the osx bundle

image

If I install with the unity package manager, the dylib is excluded

image

If I copy the runtimes and build folders back in, it doesn't stop the dll not found error.

Perhaps I need to copy the libe_sqlite3.dylib file somewhere, but I have no idea where...

@ericsink we would pay you for an hour of consultancy to help us troubleshoot, interested?

Best Tim

ericsink commented 2 years ago

(let's hold off on the paid consulting idea for the moment)

I'm pretty sure this library doesn't work with Unity. I would like to figure things out and make that happen, but I don't have any experience with Unity.

Can anyone here summarize the issues? At first glance, this looks like a target framework problem.

bricelam commented 2 years ago

IIRC, NuGetForUnity doesn't handle the runtimes directory of packages. You need to manually add it to your project (next to the lib directory), then configure the Platform settings for each native e_sqlite3 library. Here's a screenshot from a demo I did a few years ago showing how to do this:

image

ecsplendid commented 2 years ago

Thanks so much for the help, that was very useful! @bricelam

I tried this, and I now get a message saying that the .dylib is an x64, not an apple silicone. I guess this PCL library doesn't bundle the assembly for M1 anyway? But this is very useful thanks so much

image image
ericsink commented 2 years ago

SQLitePCLRaw does include a dylib for M1.

In the nuget package SQLitePCLRaw.lib.e_sqlite3, it should be at the path runtimes/osx-arm64/native/libe_sqlite3.dylib.

ecsplendid commented 2 years ago

Ah - thanks for the nudge. This might be another weird Unity NuGet behaviour. It guesses which platform you are on, and deletes the other assemblies.

I tried using the nuget command line to download your package-

image

Then copied the correct assembly in to assets, and checked the boxes as indicated by @bricelam

osx-x64
        │   └── native
        │       └── libe_sqlite3.dylib

And... it works!

image

Thank you both so much