Android 7.0 System.DllNotFoundException: /system/lib/libsqlite.so

ChristianSvrdChristianSvrd SEMember ✭✭✭
edited December 2016 in Xamarin.Android

I get this exception System.DllNotFoundException: /system/lib/libsqlite.so whenever I try to create a SQLite.Net.SQLiteConnection in android 7.0
any idea how to fix it?
I'm using these nuget pacakges:

    <packages>
      <package id="ExifLib.PCL" version="1.0.1" targetFramework="monoandroid6" />
      <package id="Microsoft.Bcl" version="1.1.10" targetFramework="monoandroid43" />
      <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="monoandroid43" />
      <package id="Newtonsoft.Json" version="7.0.1" targetFramework="monoandroid6" />
      <package id="SQLite.Net.Core-PCL" version="3.1.1" targetFramework="monoandroid6" />
      <package id="SQLite.Net-PCL" version="3.1.1" targetFramework="monoandroid6" />
      <package id="SQLiteNetExtensions" version="1.3.0" targetFramework="xamarinios1" />
      <package id="sqlite-net-pcl" version="1.2.1" targetFramework="monoandroid70" />
      <package id="SQLitePCL.bundle_green" version="0.9.3" targetFramework="monoandroid60" />
      <package id="SQLitePCL.plugin.sqlite3.android" version="0.9.3" targetFramework="monoandroid60" />
      <package id="SQLitePCL.raw" version="0.9.3" targetFramework="monoandroid60" />
      <package id="SQLitePCLRaw.bundle_green" version="1.1.1" targetFramework="monoandroid70" />
      <package id="SQLitePCLRaw.core" version="1.1.1" targetFramework="monoandroid70" />
      <package id="SQLitePCLRaw.lib.e_sqlite3.android" version="1.1.1" targetFramework="monoandroid70" />
      <package id="SQLitePCLRaw.provider.e_sqlite3.android" version="1.1.1" targetFramework="monoandroid70" />
      <package id="Xam.Plugins.Settings" version="2.5.1.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.CustomTabs" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
      <package id="Xamarin.FFImageLoading" version="2.2.5" targetFramework="monoandroid70" />
      <package id="Xamarin.FFImageLoading.Forms" version="2.2.5" targetFramework="monoandroid70" />
      <package id="Xamarin.Forms" version="2.3.3.168" targetFramework="monoandroid70" />
      <package id="Xamarin.GooglePlayServices.Ads" version="29.0.0.1" targetFramework="monoandroid60" />
      <package id="Xamarin.GooglePlayServices.Analytics" version="29.0.0.1" targetFramework="monoandroid60" />
      <package id="Xamarin.GooglePlayServices.AppIndexing" version="29.0.0.1" targetFramework="monoandroid60" />
      <package id="Xamarin.GooglePlayServices.Base" version="29.0.0.1" targetFramework="monoandroid60" />
      <package id="Xamarin.GooglePlayServices.Basement" version="29.0.0.1" targetFramework="monoandroid60" />
      <package id="Xamarin.Insights" version="1.12.3" targetFramework="monoandroid60" />
    </packages>

Best Answers

  • grierosualina.0064grierosualina.0064 RO ✭✭
    Accepted Answer
  • CameronCameron US ✭✭
    Accepted Answer

    @pallavbohara @stuart_A

    This is fixed by adding the Mono.Data.Sqlite reference on the Droid project, under the Packages tab of Edit References. This will not be checked by default even if you were using Sqlite before.

    After you've added the SQLite.Net.Platform.XamarinAndroidN package, change your DatabaseService code to the snippet below. If you are following the Xamarin.Forms implementation examples, this is probably the only place in your project that needs a code change.

    var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroidN();
    var connection = new SQLite.Net.SQLiteConnection(platform, path, false);
    return connection;
    

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    which exception?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    ah.. the one in the title...

  • KeithLongwellKeithLongwell USMember ✭✭

    I am having the same problem. It has worked fine, and continues to, on Android 4.4 - 6. But as soon as it runs on Android 7 I get this error.

    Has anyone else resolved this besides just not letting users of Android 7 use the app?

  • ChristianSvrdChristianSvrd SEMember ✭✭✭

    First remove all the dependencies you have to sqlite libs and then upgrade your SQLiteNetExtensions nuget package to the latest alpha version (check prerelease).> @KeithLongwell said:

    I am having the same problem. It has worked fine, and continues to, on Android 4.4 - 6. But as soon as it runs on Android 7 I get this error.

    Has anyone else resolved this besides just not letting users of Android 7 use the app?

  • grierosualina.0064grierosualina.0064 ROMember ✭✭
    Accepted Answer
  • pallavboharapallavbohara USMember ✭✭
    edited October 2017

    Me too getting same error....

    UNHANDLED EXCEPTION:
    10-13 15:00:00.636 I/MonoDroid(11803): System.TypeInitializationException: The type initializer for 'DataServices.Database.DatabaseHelper' threw an exception. ---> System.DllNotFoundException: /system/lib/libsqlite.so
    10-13 15:00:00.636 I/MonoDroid(11803): at (wrapper managed-to-native) SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidInternal:sqlite3_open_v2 (byte[],intptr&,int,intptr)
    10-13 15:00:00.636 I/MonoDroid(11803): at SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroid.Open (System.Byte[] filename, SQLite.Net.Interop.IDbHandle& db, System.Int32 flags, System.IntPtr zvfs) [0x00000] in <8dbf6ff85082469fb9d4dfaa9eae6b69>:0
    10-13 15:00:00.636 I/MonoDroid(11803): at SQLite.Net.SQLiteConnection..ctor (SQLite.Net.Interop.ISQLitePlatform sqlitePlatform, System.String databasePath, SQLite.Net.Interop.SQLiteOpenFlags openFlags, System.Boolean storeDateTimeAsTicks, SQLite.Net.IBlobSerializer serializer, System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary2[TKey,TValue] extraTypeMappings, SQLite.Net.IContractResolver resolver) [0x000a2] in <8f2bb39aeff94a30a8628064be9c7efe>:0
    10-13 15:00:00.636 I/MonoDroid(11803): at SQLite.Net.SQLiteConnection..ctor (SQLite.Net.Interop.ISQLitePlatform sqlitePlatform, System.String databasePath, System.Boolean storeDateTimeAsTicks, SQLite.Net.IBlobSerializer serializer, System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary2[TKey,TValue] extraTypeMappings, SQLite.Net.IContractResolver resolver) [0x00000] in <8f2bb39aeff94a30a8628064be9c7efe>:0
    10-13 15:00:00.636 I/MonoDroid(11803): at XXXXXX.Droid.SQLite_Android.XXXXXXDataServices.DbHelper.ISQLite.GetConnection () [0x0001c] in E:\XXXXXX9JuneSvn2\XXXXXX9JuneSvn\XXXXXX\XXXXXX.Android\LocalDB\SQLite_Android.cs:19
    10-13 15:00:00.636 I/MonoDroid(11803): at XXXXXXDataServices.Database.DatabaseHelper..cctor () [0x00014] in E:\XXXXXX9JuneSvn2\XXXXXX9JuneSvn\XXXXXXDataServices\Database\DatabaseHelper.cs:48
    10-13 15:00:00.636 I/MonoDroid(11803): --- End of inner exception stack trace ---
    10-13 15:00:00.636 I/MonoDroid(11803): at XXXXXX.App+d__9.MoveNext () [0x0001b] in E:\XXXXXX9JuneSvn2\XXXXXX9JuneSvn\XXXXXX\XXXXXX\App.xaml.cs:172
    10-13 15:00:00.636 I/MonoDroid(11803): --- End of stack trace from previous location where exception was thrown ---
    10-13 15:00:00.636 I/MonoDroid(11803): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
    10-13 15:00:00.636 I/MonoDroid(11803): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0
    10-13 15:00:00.636 I/MonoDroid(11803): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
    10-13 15:00:00.636 I/MonoDroid(11803): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
    10-13 15:00:00.637 I/MonoDroid(11803): at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
    10-13 15:00:00.637 I/MonoDroid(11803): at XXXXXX.App+d__6.MoveNext () [0x00079] in E:\XXXXXX9JuneSvn2\XXXXXX9JuneSvn\XXXXXX\XXXXXX\App.xaml.cs:130
    10-13 15:00:00.637 I/MonoDroid(11803): --- End of stack trace from previous location where exception was thrown ---
    10-13 15:00:00.637 I/MonoDroid(11803): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
    10-13 15:00:00.637 I/MonoDroid(11803): at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
    10-13 15:00:00.637 I/MonoDroid(11803): at Android.App.SyncContext+<>c__DisplayClass2_0.b__0 () [0x00000] in :0
    10-13 15:00:00.637 I/MonoDroid(11803): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in :0
    10-13 15:00:00.637 I/MonoDroid(11803): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in :0
    10-13 15:00:00.637 I/MonoDroid(11803): at (wrapper dynamic-method) System.Object:fbfa7f03-3e17-4071-b91b-aa6686e81c25 (intptr,intptr)
    10-13 15:00:00.645 D/Mono (11803): Assembly Ref addref HockeySDK.AndroidBindings[0xa6277860] -> System[0xa62cfe60]: 12
    10-13 15:00:00.656 W/art (11803): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable

  • pallavboharapallavbohara USMember ✭✭

    @grierosualina.0064 Hey buddy I tried

    But it also says don't forget to reference the latest Mono.Data.Sqlite in your Android project where I have to set this??

  • pallavboharapallavbohara USMember ✭✭

    @ChristianSvrd I changed my target to Android 6.0 and apk worked in Nougat device but its not the right way....also it will not list your app in PlayStore for Nougat device.

  • stuart_Astuart_A Member ✭✭

    I've encountered the same problem and it's eaten about 3 days from my rapidly approaching deadline. Works fine on Android 6.0 and under, but showed the dllnotfoundexception error message on 7.1. The app would work fine after dismissing the error, but now after attempting to follow various solutions, I've ended up with it not opening at all, where the log shows a ton of errors saying that various DLLs could not be loaded because /system/lib64/libsqlite.so was not found.

    I tried all sorts, including using the VS2017 Preview version (advice given directly by Xamarin) which COMPLETELY ruined the whole thing, I needed to uninstall the VS2017 Preview version then perform a repair/modify operation on my original VS2017, after which I discovered my project wasn't discovering anything to do with Android/SDK/ADV, so had to uninstall and reinstall all Android SDK stuff too. And this is the point at which the app won't run AT ALL on Android 7.1 (even though it was fine enough, albeit with an error message, before).

    Almost destroyed my entire project trying to sort this mess out, and still not a whiff of progress. Once again a tiny issue has ballooned into a fucking leviathan, and barely even a hint of a solution even though the issue was first noted in 2016. I've tried the advice given directly by Xamarin and it almost bricked the whole project, again. Advice from users on here isn't working either. I'm getting various "this is not compatible with mono 8.0.0" errors, and all the other stuff that usually appears in various forms in the plethora of Xamarin Forms problems I've run into.

    I will never use Xamarin tools again. Problem after problem after problem. It's like the whole thing is just a constant hodge-bodge of attempting to make it work and using hand-wavy workaround solutions that only satisfy 50% of users. The whole platform is a minefield. I barely try to do anything any more for fear of another day lost having to figure out which nuget package, or which target system, or whichever other thing, has fucked up. As it stands, my app probably won't even work on Android 7.0 and up. I'm going to have to switch to Android Studio and rewrite the lot, and shall certainly never look back at the disaster that is Xamarin. Sorry guys, you had great intentions but it just isn't working. All the fanfare about cross-platform solutions etc, it just isn't true. Cross-platform apps are limited to piffling simple things that might as well be done natively anyway, given the simplicity of the apps that Xamarin allows for.

    Native development for me next time, no more of this shit for me, sorry.

  • CameronCameron USMember ✭✭
    Accepted Answer

    @pallavbohara @stuart_A

    This is fixed by adding the Mono.Data.Sqlite reference on the Droid project, under the Packages tab of Edit References. This will not be checked by default even if you were using Sqlite before.

    After you've added the SQLite.Net.Platform.XamarinAndroidN package, change your DatabaseService code to the snippet below. If you are following the Xamarin.Forms implementation examples, this is probably the only place in your project that needs a code change.

    var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroidN();
    var connection = new SQLite.Net.SQLiteConnection(platform, path, false);
    return connection;
    
  • stuart_Astuart_A Member ✭✭
    edited February 2018

    @Cameron

    I can't, the AndroidN package won't add to the Android part of project where it's required. It clashes with various other packages and I've tried a million things to get around the issue. And if it's not clashing, it's telling me I have the wrong monoAndroid version. If I change the Android version, it tells me I have the wrong .NET version.

    Mono.Data.SQLite is added too.

    It's too late now, I've finished the project and it's going on the play store today (targeting SDK 23 and under). I ran into a ton of other issues too, all involving the usual clean/refresh/delete/restart rigmarole that Xamarin Forms demands at every turn.

    I'm never using Xamarin Forms again.

  • stuart_Astuart_A Member ✭✭

    Small update, and a rather fantastic one.

    I discovered my Android manifest was set to target API 27 (Android 8.1).

    "Too high!", I thought, because that would mean users on Android 7.0 and above would also be able to access the app, which I don't want because it doesn't work for them.

    So I went back and manually set the target to Android 6.0, API 23.

    Then my mate was having trouble getting the raw apk file to install on his phone, so I tested it on my new phone (Android 7.1), which I knew wouldn't be able to run the app but it would at least install it. The aim was to simply check that the apk was still installing as normal.

    Well the apk did install, and... the app works, on my Android 7.1 phone, with no error messages or anything! The only change I made was setting the target API to API 23 in the manifest. Ha!

    So that's it, disaster averted, and I have no idea how. My project does not include the AndroidN NuGet package, and it has been an absolute clusterfuck of hurdles and problems at every step of the way. Dare I say there really is a god after all? Heh.

    However, I don't know if the app will be available to users of Android 7.0 and above on the play store. I don't know how google play deals with the min/max targets on Android manifest files.

    Sudden dose of good news anyway. App currently working on all devices.

  • CameronCameron USMember ✭✭

    @stuart_A Good to hear you got it working. This problem only shows up when trying to target Android 7.0 and higher. There's some verbiage about it on the Xamarin.Android 7.0 release page that talks about the technical reasons.

    For others with this problem, if you need to target 7.0 and get the package conflict errors, make sure your existing packages are retargeted properly in the packages.config file to the android version your project targets.

    <package id="SQLite.Net-PCL" version="3.1.1" targetFramework="monoandroid71" />

  • SacomaniSacomani USMember ✭✭

    show this message in console!

    SQLite.Net.Platform.XamarinAndroidN 3.1.1 is not compatible with monoandroid81 (MonoAndroid,Version=v8.1). Package SQLite.Net.Platform.XamarinAndroidN 3.1.1 supports: net (.NETFramework,Version=v0.0)

  • Jean-DanielGasserJean-DanielGasser CHMember ✭✭

    Thanks to @AlessandroCaliaro , the use of sqlite-ne-pcl was the solution for me. And it does not require much change in the code.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    It's the only solution @Jean-DanielGasser . It's the "official" sqlite package for xamarin

  • wmdwmd GBMember ✭✭
    edited October 2018

    What is the current solution for this issue for a xamarin.forms Shared Project? Google now requires you to target a minimum of Android 26, so setting the target below that is no longer a solution. I am not using any SQLite nugets, I just have the SQLite.cs and SQLiteAsync.cs classes in my project.

  • wmdwmd GBMember ✭✭

    @Cameron said:
    @pallavbohara @stuart_A

    This is fixed by adding the Mono.Data.Sqlite reference on the Droid project, under the Packages tab of Edit References. This will not be checked by default even if you were using Sqlite before.

    After you've added the SQLite.Net.Platform.XamarinAndroidN package, change your DatabaseService code to the snippet below. If you are following the Xamarin.Forms implementation examples, this is probably the only place in your project that needs a code change.

    var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroidN();
    var connection = new SQLite.Net.SQLiteConnection(platform, path, false);
    return connection;
    

    How can this be done with an SQLiteAsyncConnection object? This object does not have a Platform property.

  • CameronCameron USMember ✭✭

    @wmd said:
    What is the current solution for this issue for a xamarin.forms Shared Project? Google now requires you to target a minimum of Android 26, so setting the target below that is no longer a solution. I am not using any SQLite nugets, I just have the SQLite.cs and SQLiteAsync.cs classes in my project.

    Not sure, I've long since converted all my projects to .NetStandard.

  • NicolaLoroNicolaLoro USMember ✭✭

    @ChristianSvrd ,
    may I suggest that you change the accepted answer of this topic? That may bring people on the wrong way.
    Since November 2018, Google requires minimum Android 8.0 for all apps updates. So, downgrading the target platform is not good. The right solution is what grierosualina.0064 posted. And don't forget to reference Mono.Data.Sqlite (see Cameron post above)

  • ChristianSvrdChristianSvrd SEMember ✭✭✭

    @NicolaLoro said:
    @ChristianSvrd ,
    may I suggest that you change the accepted answer of this topic? That may bring people on the wrong way.
    Since November 2018, Google requires minimum Android 8.0 for all apps updates. So, downgrading the target platform is not good. The right solution is what grierosualina.0064 posted. And don't forget to reference Mono.Data.Sqlite (see Cameron post above)

    I haven't tested them myself, but based on your suggestion I added those two posts as answers.

  • MichelangeloFrancoMichelangeloFranco ITUniversity ✭✭

    Uninstall all sqlite packages. install 'sqlite-net-pcl' (by Frank A. Krueger) latest version for all projects.

  • VictorArce.8951VictorArce.8951 MXMember ✭✭

    @AlessandroCaliaro @MichelangeloFranco Yes, Installing sqlite-net-pcl package solves the crash issue BUT...! in my case: It doesn't recognize an existing database. Looks like it creates a new database instead. I already checked the file paths and they appear to be the same. The thing is that this is an app update, not a new version, and there's no room for a data migration.

    PS. I have the same issues as everyone else in this thread. And back in the day, i got the library from adding the Sqlite.cs and SqliteAsync.cs manually.

Sign In or Register to comment.