System.DllNotFoundException:/system/lib/libsqlite.so- Xamarin Forms [英] System.DllNotFoundException: /system/lib/libsqlite.so- Xamarin Forms

查看:32
本文介绍了System.DllNotFoundException:/system/lib/libsqlite.so- Xamarin Forms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am facing SQLite issue in xamarin forms project. However SQLiteConnection I am trying to instantiating in Android platform there getting exception.

在 android & 中使用的库iOS项目

Libraries using in android & iOS project

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

menifest 文件目标版本

menifest file target versions

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

AndroidSQLite.cs 文件

AndroidSQLite.cs file

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 包的选项.共享项目屏幕截图

I have installed above libraries on solution level but in shared project, there is no option available to install Nuget packages. Shared project screen shot

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

Following this article to learn SQLite with xamarin 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] in<8dbf6ff85082469fb9d4dfaa9eae6b69>:0 在SQLite.Net.SQLiteConnection..ctor (SQLite.Net.Interop.ISQLitePlatformsqlitePlatform,System.String 数据库路径,SQLite.Net.Interop.SQLiteOpenFlags openFlags, System.BooleanstoreDateTimeAsTicks,SQLite.Net.IBlobSerializer 序列化器,System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings,System.Collections.Generic.IDictionary2[TKey,TValue]extraTypeMappings, SQLite.Net.IContractResolver 解析器) [0x000a2] in<8f2bb39aeff94a30a8628064be9c7efe>:0 在SQLite.Net.SQLiteConnection..ctor (SQLite.Net.Interop.ISQLitePlatformsqlitePlatform, System.String databasePath, System.BooleanstoreDateTimeAsTicks,SQLite.Net.IBlobSerializer 序列化器,System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings,System.Collections.Generic.IDictionary2[TKey,TValue]extraTypeMappings, SQLite.Net.IContractResolver 解析器) [0x00000] in<8f2bb39aeff94a30a8628064be9c7efe>:0

{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.IDictionary2[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.IDictionary2[TKey,TValue] extraTypeMappings, SQLite.Net.IContractResolver resolver) [0x00000] in <8f2bb39aeff94a30a8628064be9c7efe>:0

推荐答案

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

The SQLite.Net-PCL nuget you used is no longer being maintained by it's author. You need to switch to other similar package sqlite-net-pcl

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

First remove the existing SQLite.Net-PCL nuget from all projects and install the one I mentioned above. Remove all old SQLite related references from all files.

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

You need to make some changes in SQLite connection related dependency service classes. Then you may adjust some other code which relates to SQLite. Resolve the references by adding appropriate using statements for the new nuget package.

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

I got the same error and I solved it by switching to above nuget package.

注意:新的 nuget 包还没有 InsertOrReplaceAll 方法.所以如果你在之前的nuget中使用过这个方法,那么对于新的nuget,你需要创建一个InsertOrReplaceAll 扩展方法.

NOTE : The new nuget package does not have InsertOrReplaceAll method yet. So If you have used this method from previous nuget, then for the new nuget, you need to create an InsertOrReplaceAll extension method.

EDIT:获取 SQLiteConnection:

EDIT: To get the SQLiteConnection:

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

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

There is no need to pass the platform in this new nuget. Pass false if you don't want to store DateTime as Ticks.

这篇关于System.DllNotFoundException:/system/lib/libsqlite.so- Xamarin Forms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆