gpt4 book ai didi

c# - System.DllNotFoundException :/system/lib/libsqlite. 所以

转载 作者:行者123 更新时间:2023-11-30 13:43:42 25 4
gpt4 key购买 nike

我在 xamarin 表单项目中遇到 SQLite 问题。但是 SQLiteConnection 我正在尝试在 Android 平台中实例化那里出现异常。

Android & iOS 项目中使用的库

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

list 文件目标版本

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />

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;
}
}
}

获取异常

 var conn= new SQLiteConnection(plat, dpPath);

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

enter image description here

跟着这篇文章用xamarin学习SQLite xamarin forms-mvvm-sqlite-sample .

下面是完整的异常

{System.DllNotFoundException: /system/lib/libsqlite.so at (wrapper managed-to-native) SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidInternal.sqlite3_open_v2(byte[],intptr&,int,intptr) 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 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.IDictionary
2[TKey,TValue] extraTypeMappings, SQLite.Net.IContractResolver resolver) [0x000a2] in <8f2bb39aeff94a30a8628064be9c7efe>:0 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.IDictionary
2[TKey,TValue] extraTypeMappings, SQLite.Net.IContractResolver resolver) [0x00000] in <8f2bb39aeff94a30a8628064be9c7efe>:0

最佳答案

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

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

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

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

注意:新的 nuget 包还没有 InsertOrReplaceAll 方法。因此,如果您从以前的 nuget 中使用过这种方法,那么对于新的 nuget,您需要创建一个 InsertOrReplaceAll extension method。 .

编辑:获取 SQLiteConnection:

public SQLiteConnection GetConnection()
{
return new SQLiteConnection(dpPath, false);
}

在这个新的nuget中不需要传递平台。如果您不想将 DateTime 存储为 Ticks,请传递 false

关于c# - System.DllNotFoundException :/system/lib/libsqlite. 所以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52052631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com