ericsink / SQLitePCL.raw

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

Using SEE build #466

Closed ericsink closed 2 years ago

ericsink commented 2 years ago

@ericsink Apologies for not being clear. We are using "Azure.Mobile.Client" for offline sync in Xamarin.Forms. I purchased SEE from sqlite team (as I wanted to use SEE instead of SQLCipher). I then created a custom build of SQLite and placed in XAMARIN FORMS under the Android project under "/lib/x86/libsqliteX.so". Similarly added appropriate build file in Xamarin's iOS project too. I found that "Microsoft.Azure.Mobile.Client.SQLiteStore" uses "SQLitePCLRaw.bundle_green" and they use:

SQLitePCLRawHelpers.GetSqliteConnection(dbPath) This function further calls: Batteries_V2.Init();

This INIT call infact would call:

For Android: SQLitePCLRaw.provider.e_sqlite3 SQLitePCLRaw.lib.e_sqlite3.android

For iOS: SQLitePCLRaw.provider.sqlite3 I guess.

Now, as we're using a custom build of SQLITE as .so file in Android, I cannot use Batteries_V2.Init();. Instead, I removed "SQLitePCLRaw.bundle_green" and installed SQLPclRaw.core and SQLite3Provider_dynamic_cdecl.

Then I removed Batteries_V2.Init(); and replaced it with:

SQLite3Provider_dynamic_cdecl.Setup("sqlite3", new NativeLibraryAdapter("libsqliteX.so")); raw.SetProvider(new SQLite3Provider_dynamic_cdecl());

For NativeLibraryAdapter, I am using SQLITEPCL.NATIVELIBRARY as this is not .net core:

class NativeLibraryAdapter : IGetFunctionPointer { readonly IntPtr _library;

    public NativeLibraryAdapter(string name)
        => _library = NativeLibrary.Load(name, typeof(NativeLibraryAdapter).Assembly, 0);//Assembly.GetExecutingAssembly()

    public IntPtr GetFunctionPointer(string name)
        => NativeLibrary.TryGetExport(_library, name, out var address)
            ? address
            : IntPtr.Zero;
}

The things are not working. The file is not being read and the following line: SQLite3Provider_dynamic_cdecl.Setup("sqlite3", new NativeLibraryAdapter("libsqliteX.so"));

breaks the Mobile APP.

Could you please give me a direction that how I can use "libsqliteX.so" in Xamarin Android using SQLitePCLRawHelpers?

Your guidance will help me a lot. Please guide.

Thanks.

Angel

Originally posted by @angelrishi in https://github.com/ericsink/SQLitePCL.raw/issues/341#issuecomment-1015483664

ericsink commented 2 years ago

You are heading in the right direction by removing the bundle and Batteries.Init() and copying code from there into your app.

Probably something is going wrong with NativeLibrary.Load() being unable to find your custom library. You may want to put some debugging in there to see why it is failing.

Is libsqliteX.so being placed in the right spot?

Does the OS need "libsqliteX" instead of with the .so suffix?

Do you have builds of libsqliteX for the various CPUs you need to support?

ericsink commented 2 years ago

Closing for lack of activity