dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.68k stars 3.16k forks source link

EFCore on Android. Require 'libmod_spatialite' instead of 'mod_spatialite'. #24094

Open AndroidEFCoreLover opened 3 years ago

AndroidEFCoreLover commented 3 years ago

Hi,

I cannot use EF Core on Android device, cause I cannot deploy 'mod_spatialite' with APK. I see Android only allows me to deploy *.so files with the name starting with "lib".

And, in: https://github.com/dotnet/efcore/blob/b8483772f298f5ada8b2b5253a9904c93c34919f/src/EFCore.Sqlite.Core/Infrastructure/SpatialiteLoader.cs#L100

we specifically require the name, without the 'lib'.

Is it possible to change the name, to allow it to be used on all platforms?

AndroidEFCoreLover commented 3 years ago

Someone describes the restrictions in more detail: https://developercommunity.visualstudio.com/content/problem/841599/androidnativelibrary-so-files-will-not-deploy-to-a.html

ajcvickers commented 3 years ago

/cc @bricelam

bricelam commented 3 years ago

Note for triage: Looks like SQLite only adds the extension (dll, so, dylib, etc.) and not the 'lib' prefix like I initially thought.

A couple of thoughts...

We could expose an option to disable our call to LoadExtension. It's kind of possible today using some lower-level, pubternal APIs:

https://github.com/dotnet/efcore/blob/91655d5e3e7657487cbc143ae7fd98a829e3b938/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs#L27-L36

This would be helpful in this scenario, but also if you're using SpatiaLite directly as your native SQLite library (not as an extension).

We could also try loading libmod_spatialite.so if the just mod_spatialite fails (similar to how .NET probes during P/Invoke).

We could also detect if we're running on Android at runtime and only look for libmod_spatialite...

P.S. I'd love it if you could look through https://github.com/bricelam/mod_spatialite-NuGet/issues/6 and add any additional information you might have.

AndroidEFCoreLover commented 3 years ago

I switched the last to false, and then on creation of each context, I enable loading of extensions, and load the .so we need. Did a round trip on point geometry on android.