2017-10-09 6 views
0

私はXamarinを初めて使用していて、APPを作成しようとしています。私は7未満のAndroidでSQLiteデータベースを作成しようとすると、それは完全に動作します。しかし、私が7と7.1でデータベースを作成しようとすると、エラーが発生します。この問題については、 link in Xamarin discussion forumと私はコードAndroidでデータベース接続に失敗する7 +

public SQLite.Net.SQLiteConnection GetConnection() 
    { 

     var sqliteFilename = "ADB.db3"; 
     string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); 
     var path = Path.Combine(documentsPath, sqliteFilename); 

     if (!File.Exists(path)) 
     { 
      using (var br = new BinaryReader(Android.App.Application.Context.Assets.Open("ATSDB.db3"))) 
      { 
       using (var bw = new BinaryWriter(new FileStream(path, FileMode.Create))) 
       { 
        byte[] buffer = new byte[2048]; 
        int length = 0; 
        while ((length = br.Read(buffer, 0, buffer.Length)) > 0) 
        { 
         bw.Write(buffer, 0, length); 
        } 
       } 
      } 
     } 



     // var plat = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(); 
     var plat = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroidN(); 

     var conn = new SQLite.Net.SQLiteConnection(plat, path); 
     // Return the database connection 
     return conn; 

    } 

を統合**この行で、私はエラーに** var conn = new SQLite.Net.SQLiteConnection(plat, path); // Return the database connection

を取得しています、私はエラーの下に取得しています:

{System.DllNotFoundException: libsqlite3_xamarin  
    at (wrapper managed-to-native) SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidNInternal:sqlite3_open_v2 (byte[],intptr&,int,intptr) 

    at SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidN.Open (System.Byte[] filename, SQLite.Net.Interop.IDbHandle& db, System.Int32 flags, System.IntPtr zvfs) [0x00000] in <360d65bfaa3e44c0b2b5840d827a452d>: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.IDictionary`2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary`2[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.IDictionary`2[TKey,TValue] tableMappings, System.Collections.Generic.IDictionary`2[TKey,TValue] 
    extraTypeMappings, SQLite.Net.IContractResolver resolver) [0x00000] 
    in <8f2bb39aeff94a30a8628064be9c7efe>:0 
    at ATSDriver.Droid.SqliteService.GetConnection() [0x000b5] 
    in E:\Projects\DriverApp\Source\ATSDriver\ATSDriver\ATSDriver.Android\SqliteService.cs:52 

at ATSDriver.DataAccess..ctor() [0x00009] in E:\Projects\DriverApp\Source\ATSDriver\ATSDriver\ATSDriver\DataAccess.cs:17 } 

希望いくつかの私はこれを解決するのを助けることができます。前もって感謝します。

答えて

0

これはSqlite.Netのバグです。hereのバグのリストは、特にthis oneです。アンドロイドはアンドロイド7の後にファイルへのアクセスを制限し、これは要するに

Sqlite.NetパッケージパッケージSqlite.Netに影響を与えた所有者がAndroidの7 REFと動作するように更新されていませんと死んでいる:私はあなたに切り替える提案https://github.com/oysteinkrog/SQLite.Net-PCL/issues/370

Sqlite-Netは、Android 7+をサポートしています

+0

あなたのコメントのおかげでありがとう、私はこのアプリのすべての部分を完了し、最後にこのような非常に痛いエラーを取得しているので、これを使用する方法の例のリンクです –

+0

@AグーテアTheresはこれを行うためのガイドがありません。旧式の 'Sqlite.Net'ナゲットパッケージを削除し、代わりに' Sqlite-Net'ナゲットパッケージをインストールするというケースがあります。次に、エラーを構築して修正します。ほとんどのエラーは単に名前空間を変更するだけです。それは痛みですが、 'Sqlite.Net'のすべてのユーザーがそこにいました – user1

関連する問題