3

On our Xamarin Android project we are trying to switch from sqlite-net to official sqlite-net-pcl package.

enter image description here

However after this switch when creating a new SQLiteConnection I am getting following exception:

The type initializer for 'SQLite.SQLiteConnection' threw an exception. ---> System.DllNotFoundException: e_sqlite3

Full exception:

Xamarin caused by: android.runtime.JavaProxyThrowable: System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception. ---> 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 :0 at SQLitePCL.raw.SetProvider (SQLitePCL.ISQLite3Provider imp) [0x00000] in <4472a4c16754425197d915f39ebd937e>:0 at SQLitePCL.Batteries_V2.Init () [0x0000d] in <1125db7e18f0475797b2764ec6653cf1>:0 at SQLite.SQLiteConnection..cctor () [0x00000] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:171 --- End of inner exception stack trace --- at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method) at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30) at android.view.View.performClick(View.java:4780) at android.view.View$PerformClick.run(View.java:19866) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

In the log I can see following info:

12-01 10:43:05.356 D/Mono (11194): DllImport attempting to load: 'e_sqlite3'. 12-01 10:43:05.358 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3" not found'. 12-01 10:43:05.360 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so" not found'. 12-01 10:43:05.360 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3" not found'. 12-01 10:43:05.360 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3.so" not found'. 12-01 10:43:05.360 D/Mono (11194): DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'. 12-01 10:43:05.361 D/Mono (11194): DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3.so" not found'. 12-01 10:43:05.361 D/Mono (11194): DllImport error loading library 'e_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/e_sqlite3" not found'. 12-01 10:43:05.362 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3" not found'. 12-01 10:43:05.364 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so" not found'. 12-01 10:43:05.364 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3" not found'. 12-01 10:43:05.364 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3.so" not found'. 12-01 10:43:05.364 D/Mono (11194): DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'. 12-01 10:43:05.364 D/Mono (11194): DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3.so" not found'. 12-01 10:43:05.365 D/Mono (11194): DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'. 12-01 10:43:05.365 W/Mono (11194): DllImport unable to load library 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'. 12-01 10:43:05.365 D/Mono (11194): DllImport attempting to load: 'e_sqlite3'. 12-01 10:43:05.366 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3" not found'. 12-01 10:43:05.368 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so" not found'. 12-01 10:43:05.368 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3" not found'. 12-01 10:43:05.368 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3.so" not found'. 12-01 10:43:05.368 D/Mono (11194): DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'. 12-01 10:43:05.368 D/Mono (11194): DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3.so" not found'. 12-01 10:43:05.369 D/Mono (11194): DllImport error loading library 'e_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/e_sqlite3" not found'. 12-01 10:43:05.370 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3" not found'. 12-01 10:43:05.371 D/Mono (11194): DllImport error loading library '/storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.override/libe_sqlite3.so" not found'. 12-01 10:43:05.372 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3" not found'. 12-01 10:43:05.372 D/Mono (11194): DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86//system/lib/libe_sqlite3.so" not found'. 12-01 10:43:05.372 D/Mono (11194): DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'. 12-01 10:43:05.372 D/Mono (11194): DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3.so" not found'. 12-01 10:43:05.373 D/Mono (11194): DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'. 12-01 10:43:05.373 W/Mono (11194): DllImport unable to load library 'dlopen failed: library "/data/app/com.psonar.android-1/lib/x86/libe_sqlite3" not found'.

It's obvious what's wrong: System.DllNotFoundException: e_sqlite3 however I can't find any relevant info that would lead to solving this problem.

I checked my nuget packages and they all seem to be correctly installed.

enter image description here

I checked the package location and it is all correct. Very unsure where the cause might be.

EDIT: Reported to the author of the package in here: https://github.com/praeclarum/sqlite-net/issues/478

Jakub Holovsky
  • 6,543
  • 10
  • 54
  • 98

2 Answers2

7

The nuget package had to be installed in our main droid app project as well. If it is installed in a solution project which is not the app start project then it creates these problems.

Jakub Holovsky
  • 6,543
  • 10
  • 54
  • 98
  • 1
    Would you please elaborate? I'm having a hard time understanding your answer and I believe I'm having the same issue you experienced. – HappyCoding Jul 17 '17 at 18:43
  • @HappyCoding I think `@Jakub Holonsky` is mean: If you have multiple project in your solution, and project1 is the startup project, then make sure you run the `SQLite` package on the project1 (startup project). I had the same issue with `.NET Library` and a `.NET 4.8 Project` both within same solution. I followed [this](https://docs.microsoft.com/en-us/ef/core/get-started/?tabs=visual-studio) tutorial on Standard library project. But, I had to run the `Microsoft.EntityFrameworkCore.Sqlite` and `Microsoft.EntityFrameworkCore.Design` packages on both the projects of the solution. Hope it works. – nam May 21 '20 at 01:57
  • @JakubHolovsky Your solution worked (thank you) in my similar scenario as described in my above comment. – nam May 21 '20 at 01:59
-1

I know that's an old post, and sorry for resume that, To answer @sagar-panwala that cannot fix the problem, ther easyest way is to fix that problem without become mad with nu-get plugins is set the .droid project as "StartupProject" when compiling for android:

enter image description here

Probably there was an error in the original nuget package.

Legion
  • 760
  • 6
  • 23