System.DllNotFoundException:/system/lib/libsqlite.so- Xamarin形式

Arv*_*iya 3 c# sqlite xamarin xamarin.forms

我在xamarin表单项目中面临SQLite问题。但是SQLiteConnection我试图在Android平台上实例化那里越来越异常。

在Android和iOS项目中使用的库

  • SQLite.Net-PCL 3.1.1
  • SQLite.Net.Core-PCL 3.1.1

清单文件目标版本

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
Run Code Online (Sandbox Code Playgroud)

AndroidSQLite.cs文件

using SQLite;
using SQLite.Net;
using System.IO;
namespace XamarinTestList.Droid.Implementations
{
public class AndroidSQLite : ISQLite
{
    public SQLiteConnection GetConnection()
    {
        string documentPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
        var path = Path.Combine(documentPath, DatabaseHelper.DbFileName); //DbFileName="Contacts.db"
        var plat = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
        string dpPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "user.db3");
        var conn= new SQLiteConnection(plat, dpPath);
        return conn;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

在获取例外

 var conn= new SQLiteConnection(plat, dpPath);
Run Code Online (Sandbox Code Playgroud)

我已经在解决方案级别上安装了上述库,但是在共享项目中,没有可用于安装Nuget软件包的选项。共享项目的屏幕截图

在此处输入图片说明

在本文之后,可以通过xamarin学习SQLite xamarin形式-mvvm-sqlite-sample

以下是完全例外

{System.DllNotFoundException:/system/lib/libsqlite.so,位于(包装器托管到本地)SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidInternal.sqlite3_open_v2(byte [],intptr&,int,intptr),位于SQLite.Net.Platform .XamarinAndroid.SQLiteApiAndroid.Open(SQLite.Net.SQLiteConnection上<8dbf6ff85082469fb9d4dfaa9eae6b69>:0中的<0x00000](System.Byte []文件名,SQLite.Net.Interop.IDbHandle&db,System.Int32标志,System.IntPtr zvfs)[0x00000] ctor(SQLite.Net.Interop.ISQLitePlatform sqlitePlatform,System.String databasePath,SQLite.Net.Interop.SQLiteOpenFlags openFlags,System.Boolean storeDateTimeAsTicks,SQLite.Net.IBlobSerializer序列化程序,System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary在SQLite.Net.SQLiteConnection..ctor(SQLite.Net.Interop.ISQLitePlatform sqlitePlatform,System.String数据库)的<8f2bb39aeff94a30a8628064be9c7efe>:0中的2 [TKey,TValue] extraTypeMappings,SQLite.Net.IContractResolver解析器)[0x000a2]布尔值storeDateTimeAsTicks,SQLite.Net.IBlobSerializer序列化程序,System.Collections.Generic.IDictionary 2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary2 [TKey,TValue] extraTypeMappings,SQLite.Net.IContractResolver解析程序)[0x00000]在<8f2bb39aeff94a30a8628064be9c7efe>:0中

Mil*_*anG 7

您使用的SQLite.Net-PCL nuget不再由其作者维护。您需要切换到其他类似的软件包sqlite-net-pcl

首先SQLite.Net-PCL从所有项目中删除现有的nuget,然后安装我上面提到的那个。SQLite从所有文件中删除所有旧的相关引用。

您需要对SQLite与连接相关的依赖项服务类进行一些更改。然后,您可以调整与相关的其他代码SQLite。通过为新的nuget包添加适当的using语句来解析引用。

我遇到了同样的错误,并通过切换到上述nuget包解决了该错误。

注意:新的nuget软件包尚无InsertOrReplaceAll方法。因此,如果您从以前的nuget中使用了此方法,那么对于新的nuget,您需要创建一个InsertOrReplaceAll扩展方法

编辑:要获取SQLiteConnection:

public SQLiteConnection GetConnection()
{
    return new SQLiteConnection(dpPath, false);
}
Run Code Online (Sandbox Code Playgroud)

无需在这个新的nuget中传递平台。通过false如果你不想日期时间存储为蜱。