Using SQLite for EF7 on Android 7+

In my project I use a package Microsoft.EntityFrameworkCore.SQLitefrom NuGet. But for Android 7+, the application crashes withunauthorized access to "/system/lib64/libsqlite.so".

This is due to the fact that Android 7 does not allow you to create your own libraries other than those in the NDK (as I understand it). Also see this issue: https://github.com/aspnet/EntityFramework/issues/7777 .

So, I’ve been researching the Internet for about 2 days and tried unsuccessfully a bunch of things to get EFCore to work on Android 7. One of them was updating to the preview version v2.0.0-preview1-final. But this led to other problems, like the following, where the application was compiled, but crashed when deployed / launched on the emulator:

06-21 09:58:18.970 D/Mono    ( 3632): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
06-21 09:58:18.970 F/monodroid-assembly( 3632): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
06-21 09:58:18.970 F/monodroid-assembly( 3632): This might be due to an invalid debug installation.

Then I tried to manually add the “System.Runtime.CompilerServices.Unsafe” NuGet package to my project, but it did not fix the problem. I mixed up a lot, tried different build parameters and the like, and actually got an application that works with the EFCore preview package on the Android 7 emulator. However, after cleaning and restoring the project, the error appeared again.

Any help on how to get EFCore Sqlite to work on Android 7?

I am using Visual Studio 2017 with Xamarin.Android 7.3.1.2

I created a sample project to reproduce the problem: https://github.com/tipa/EFCoreSample - Basically just started with the basic Android template from VS and the Nuget package was added

+4
2

, , , , , , .

Xamarin.Forms EntityFrameworkCore SQLite. - .NetStandard 1.6 ( PCL .NetFramework .NetStandard, EntityFrameworkCore).

, , , :

  • "Microsoft.EntityFrameworkCore" "Microsoft.EntityFrameworkCore.SQLite" "1.1.1" "2.0.0-preview1-final" ( , .NetStandard 1.6) DAL ( PCL, , UoW, )

  • "Microsoft.Data.Sqlite" ( ) "1.1.1" "2.0.0-preview1-final" Xamarin.Forms Android

EntityFrameworkCore 2.x.x Android 7+ libsqlite.so, 1.x.x .

, , , .

+1

, .

Xamarin.Forms .Net Standard 2.0 libs EFCore SQLite. , , csproj Android PropertyGroup:

<PropertyGroup>
  <NoWarn>$(NoWarn);NU1605</NoWarn>
</PropertyGroup>

System.Runtime.CompilerServices.Unsafe csproj:

<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.3.0" />

Android.

: https://developercommunity.visualstudio.com/content/problem/152947/xamarin-android-run-error-could-not-load-assembly.html

0

Source: https://habr.com/ru/post/1679795/


All Articles