【发布时间】:2019-02-02 18:40:26
【问题描述】:
我在 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" />
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 包的选项。共享项目屏幕截图
按照本文学习使用 xamarin 的 SQLite xamarin forms-mvvm-sqlite-sample.
下面的完全例外
{System.DllNotFoundException: /system/lib/libsqlite.so at (wrapper 托管到本地) SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidInternal.sqlite3_open_v2(byte[],intptr&,int,intptr) 在 SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroid.Open (System.Byte[] 文件名,SQLite.Net.Interop.IDbHandle& db, System.Int32 标志,System.IntPtr zvfs) [0x00000] 在 :0 在 SQLite.Net.SQLiteConnection..ctor (SQLite.Net.Interop.ISQLitePlatform sqlitePlatform,System.String 数据库路径, SQLite.Net.Interop.SQLiteOpenFlags openFlags, System.Boolean storeDateTimeAsTicks,SQLite.Net.IBlobSerializer 序列化器, System.Collections.Generic.IDictionary
2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary2[TKey,TValue] extraTypeMappings,SQLite.Net.IContractResolver 解析器)[0x000a2] 在 :0 在 SQLite.Net.SQLiteConnection..ctor (SQLite.Net.Interop.ISQLitePlatform sqlitePlatform,System.String 数据库路径,System.Boolean storeDateTimeAsTicks,SQLite.Net.IBlobSerializer 序列化器, System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary2[TKey,TValue] extraTypeMappings,SQLite.Net.IContractResolver 解析器)[0x00000] 在 :0
【问题讨论】:
-
您是否在平台和共享代码项目上都安装了 NuGet?
-
@Gerald Versluis- 我跨项目添加的包(我在添加包时选择了 3 个项目,包括共享项目)。但似乎没有在共享项目中安装包的选项。查看我更新的问题,我在其中添加了共享项目的屏幕截图。
-
你试过用 sqlite-net-pcl 包代替吗?
-
@BrunoCaceiro 我以前没试过。但是现在当我安装它时,在更改了几个命名空间后,
SQLite.Net.Platform出现错误,平台不可用。 -
使用 sqlite-net-pcl 包:github.com/praeclarum/sqlite-net 你使用的 Lib 已经 2 年没有更新了。
标签: c# sqlite xamarin xamarin.forms