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

问题描述

我在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

清单文件目标版本

<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的SQLite. xamarin形式-mvvm-sqlite-sample

Following this article to learn SQLite with xamarinxamarin forms-mvvm-sqlite-sample.

下面是完全例外

推荐答案

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,您需要创建一个.

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.

编辑:要获取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形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:54