【发布时间】:2017-09-30 11:47:08
【问题描述】:
我在Xamarin Forms Portable 项目中使用Sqlite,并且我在iOS 和UWP 上成功运行了我的应用程序。在 Android 上,我可以在 Android 6.0 模拟器上运行我的应用程序,但在 Android Oreo 中,虽然安装了应用程序,但它在启动时会崩溃。我面临以下问题。
问题:
android.runtime.JavaProxyThrowable: at (wrapper managed-to-native) 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.SQLiteConnectionWithLock..ctor (SQLite.Net.Interop.ISQLitePlatform sqlitePlatform, SQLite.Net.SQLiteConnectionString 连接字符串, System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary2[TKey,TValue] extraTypeMappings) [0x0002e] 在 :0 在 project.Models.Database+c__DisplayClass1_0.<.ctor>b__0 () [0x0001d] 在 :0 处 SQLite.Net.Async.SQLiteAsyncConnection.GetConnection () [0x00000] 在 :0 在 SQLite.Net.Async.SQLiteAsyncConnection+c__DisplayClass11_0.b__0 () [0x00006] 在 :0 处 System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in :0 在 System.Threading.Tasks.Task.Execute() [0x00010] 中 :0 在 mono.java.lang.RunnableImplementor.n_run(本机方法)在 mono.java.lang.RunnableImplementor.run (RunnableImplementor.java:30)
在 android.os.Handler.handleCallback (Handler.java:789) 在 android.os.Handler.dispatchMessage (Handler.java:98) 在 android.os.Looper.loop (Looper.java:164) 在 android.app.ActivityThread.main (ActivityThread.java:6541) 在 java.lang.reflect.Method.invoke(本机方法)在 com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240) 在 com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767)
为了创建连接:
public Database(string databaseName)
{
var pathToDatabaseFile = DependencyService.Get<Interfaces.ISQLite>().GetLocalPathToFile(databaseName);
var platform = DependencyService.Get<Interfaces.IPlatformProvider>().GetPlatform();
_connection = new SQLiteAsyncConnection(() =>
new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(pathToDatabaseFile, false)));
_connection.CreateTableAsync<SqlitePage>().Wait();
}
在每个项目中实现GetPlatform 和GetLocalPathToFile:
return new SQLitePlatformAndroid();
和
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), fileName);
我用于 Sqlite 的包是:
- SQLite.Net.Async-PCL
- SQLite.Net.Core-PCL
- SQLite.Net-PCL
有什么想法吗?
【问题讨论】:
标签: sqlite exception xamarin xamarin.forms android-8.0-oreo