SQLite System.DllNotFoundException: e_sqlite3 using sqlite-n



您好,我正在尝试在Xamarin Forms项目中使用SQLite。但是我很难让它工作。我将提供有关我的项目配置的信息:

  1. Xamarin 版本 -> 4.6.0.726
  2. 代码共享策略 ->.NET 标准
  3. sqlite-net-pcl 1.6.292

问题:当我尝试获取连接时,会引发以下异常 ->{system.typeinitializationexception:'sqlite.sqliteconnection' 的类型初始值设定项抛出异常。 ---> system.dllnotfoundexception: e_sqlite3 at (wrapper managed-to-native( sqlitepcl.sqlite3provider_e_sqlite3+nativemethods.sqlite3_libversion_number(( at sqlitepcl.sqlite3provider_e_sqlite3.sqlitepcl.isqlite3provider.sqlite3_libversion_number (( [0x00000] in :0at sqlitepcl.raw.setprovider (sqlitepcl.isqlite3provider imp( [0x00008] in :0at sqlitepcl.batteries_v2.init (( [0x00005] in :0at sqlite.sqliteconnection..cctor (( [0x00016] 在 <84b9c9e630fa45bd8ac799333976ebbf>:0 --- 在 sqlite.sqliteconnectionwithlock ---的内部异常堆栈跟踪结束。CTOR (sqlite.sqliteconnectionstring connectionstring( [0x0000b] in <84b9c9e630fa45bd8ac799333976ebbf>:0 at sqlite.sqliteconnectionpool+entry.connect (( [0x0001c] in <84b9c9e630fa45bd8ac799333976ebbf>:0 at sqlite.sqliteconnectionpool.getconnection (sqlite.sqliteconnectionstring connectionstring( [0x00048] in <84b9c9e630fa45bd8ac799333976ebbf>:0 at sqlite.sqliteasyncconnection.getConnection (( [0x00005] in <84b9c9e630fa45bd8ac799333976ebbf>:0在 sqlite.sqliteasyncconnection.get_tracer (( [0x00000] 在 <84b9c9e630fa45bd8ac799333976ebbf>:0 }

我做了深入的研究,但我没有发现任何适合我的东西。我访问的上一篇文章是这样的:Android - 'SQLite.SQLiteConnection' 的类型初始值设定项抛出了一个异常。---> System.DllNotFoundException:e_sqlite3接受的答案只是说在Android项目上安装金块将解决问题(我已经做过的事情(

我将展示一些代码以及我的金块的外观。 机器人包

<package id="sqlite-net-pcl" version="1.6.292" targetFramework="monoandroid90" />
<package id="SQLitePCLRaw.bundle_green" version="2.0.1" targetFramework="monoandroid90" />
<package id="SQLitePCLRaw.core" version="2.0.1" targetFramework="monoandroid90" />
<package id="SQLitePCLRaw.lib.e_sqlite3" version="2.0.1" targetFramework="monoandroid90" />
<package id="SQLitePCLRaw.lib.e_sqlite3.osx" version="1.1.14" targetFramework="monoandroid90" />
<package id="SQLitePCLRaw.provider.e_sqlite3" version="2.0.1" targetFramework="monoandroid90" />

共享代码项目包

<package id="sqlite-net-pcl" version="1.6.292" targetFramework="portable45-net45+win8+wpa81" />
<package id="SQLitePCLRaw.bundle_green" version="1.1.13" targetFramework="portable45-net45+win8+wpa81" />
<package id="SQLitePCLRaw.core" version="1.1.13" targetFramework="portable45-net45+win8+wpa81" />
<package id="SQLitePCLRaw.lib.e_sqlite3.osx" version="1.1.14" targetFramework="portable45-net45+win8+wpa81" />

用于获取路径的接口

using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UISampleApp.Interfaces
{
public interface ISQLitePlatform
{
SQLiteConnection GetConnection();
SQLiteAsyncConnection GetConnectionAsync();
String GetPath();
}
}

机器人实现

using System;
using System.IO;
using Android.OS;
using SQLite;
using SQLitePCL;
using UISampleApp.Interfaces;
using UISampleApp.Models;
[assembly: Xamarin.Forms.Dependency(typeof(UISampleApp.Droid.Implementations.SQLitePlatform))]
namespace UISampleApp.Droid.Implementations
{
public class SQLitePlatform : ISQLitePlatform
{
public string GetPath() {
var dbName =Constantes.DatabaseFileName;
var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),dbName);
return path;
}
public SQLiteConnection GetConnection()
{
return new SQLiteConnection(GetPath());
}
public SQLiteAsyncConnection GetConnectionAsync()
{
return new SQLiteAsyncConnection(GetPath());
}
}
}

生成异常的代码

string path = DependencyService.Get<ISQLitePlatform>().GetPath();
SQLite.SQLiteAsyncConnection x = DependencyService.Get<ISQLitePlatform>().GetConnectionAsync();
try
{
await x.Table<TodoItem>().ToListAsync();
}
catch (Exception e)
{
throw e;
}

如果需要更多信息,我希望有人可以帮助我,只要告诉我,我会提供。 PS:在使用 PCL 的共享代码策略工作的项目上做同样的事情,但我需要在具有 .NET 标准作为共享代码策略的项目中工作。谢谢

GitHub: https://github.com/jesse0099/Hackathon2019-Movil.git

为我解决问题的是从我的项目中删除所有SQLitePCLRaw软件包,只保留sql-net-pcl。这在毛伊岛有效。

最新更新