gilzoide / unity-sqlite-net

SQLite-net for Unity, supports Windows, Linux, macOS, iOS, tvOS, visionOS, Android and WebGL
MIT License
51 stars 5 forks source link

Unity 2022.3.27f1 / SQLite-net 1.0.0-preview10 — DllNotFoundException #11

Closed SergeyBaryshev closed 4 months ago

SergeyBaryshev commented 4 months ago

Hello Gil! I have simple method in Unity project:

private SQLiteConnection CreateDatabase()
{
    var db = new SQLiteConnection(Path.Combine(Application.persistentDataPath, "Cache.db"), true);
    db.TableChanged += TableChanged;
    db.CreateTable<User>(CreateFlags.ImplicitPK);
    db.CreateTable<OfflineUser>(CreateFlags.ImplicitPK);
    return db;
}

On Windows it's works perfectly, but when i build and run on Android, i got this exception on first line of this method:

DllNotFoundException: gilzoide-sqlite-net assembly: type: member:(null) SQLite.SQLite3..cctor () (at ./Library/PackageCache/com.gilzoide.sqlite-net@3a952ebe4f/Runtime/SQLiteConfig.Log.cs:33) Rethrow as TypeInitializationException: The type initializer for 'SQLite.SQLite3' threw an exception. SQLite.SQLiteConnection..ctor (SQLite.SQLiteConnectionString connectionString) (at ./Library/PackageCache/com.gilzoide.sqlite-net@3a952ebe4f/Runtime/sqlite-net/SQLite.cs:292) SQLite.SQLiteConnection..ctor (System.String databasePath, System.Boolean storeDateTimeAsTicks) (at ./Library/PackageCache/com.gilzoide.sqlite-net@3a952ebe4f/Runtime/sqlite-net/SQLite.cs:251)

If you need more some specific info, just let me know!

gilzoide commented 4 months ago

Hey @SergeyBaryshev, thanks for the report! It's been some time since I tested this package on Android, maybe something broke from previous versions to the current one 🤔 Maybe you can look into the generated APK or the gradle project (if you are using Unity's default build pipeline, it's in Library/Bee/Android/Prj/IL2CPP/Gradle) and check if the libgilzoide-sqlite-net.so library is there somewhere at least. I'll probably look into this over the weekend.

SergeyBaryshev commented 4 months ago

I searched the "libgilzoide-sqlite-net.so" in Gradle folder, so it's found in:

image

I tried to recompile the Android build using either "IL2CPP" or "Mono", but this time I get a slightly different error:

DllNotFoundException: Unable to load DLL 'gilzoide-sqlite-net'. Tried the load the following dynamic libraries: Unable to load dynamic library 'gilzoide-sqlite-net' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "gilzoide-sqlite-net" not found SQLite.SQLite3.Config (System.Int32 option, System.IntPtr logFunc, System.IntPtr userdata) (at <00000000000000000000000000000000>:0) SQLite.SQLiteConnection..ctor (SQLite.SQLiteConnectionString connectionString) (at <00000000000000000000000000000000>:0) ... Rethrow as TypeInitializationException: The type initializer for 'SQLite.SQLite3' threw an exception. SQLite.SQLiteConnection..ctor (SQLite.SQLiteConnectionString connectionString) (at <00000000000000000000000000000000>:0)

I hope it helps.

gilzoide commented 4 months ago

Thanks for the additional info. Maybe you have the same problem as #13. If this is the case, I think I know how to fix it. Will keep you posted.

Edit: I got the same error as you, and it's not the same as the linked issue. I'll try some stuff here and see how it goes.

gilzoide commented 4 months ago

Hehe, enabling the "debug" logs in logcat showed the error about missing symbols, so the issues seem to be the same after all. Adding -lm to SQLite native build seems to solve this. I'll open a PR fixing this soon.

gilzoide commented 4 months ago

Version 1.0.0-preview11 should work on Android now, please let me know if it works for you. Cheers \o/

SergeyBaryshev commented 4 months ago

Hey @gilzoide I had checked preview11 and it works like a charm, building with ILL2CPP and Mono. Thanks for your work!