Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AndroidEFCoreLover opened this issue Feb 9, 2021 · 4 comments

Comments

@AndroidEFCoreLover
Copy link

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:

sqliteConnection.LoadExtension("mod_spatialite");

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
Copy link
Author

@ajcvickers
Copy link
Contributor

/cc @bricelam

@bricelam
Copy link
Contributor

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:

var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;
var infrastructure = (IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder;
#pragma warning disable EF1001 // Internal EF Core API usage.
// #20566
var sqliteExtension = coreOptionsBuilder.Options.FindExtension<SqliteOptionsExtension>()
?? new SqliteOptionsExtension();
var ntsExtension = coreOptionsBuilder.Options.FindExtension<SqliteNetTopologySuiteOptionsExtension>()
?? new SqliteNetTopologySuiteOptionsExtension();
infrastructure.AddOrUpdateExtension(sqliteExtension.WithLoadSpatialite(true));

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 bricelam/mod_spatialite-NuGet#6 and add any additional information you might have.

@AndroidEFCoreLover
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants