问题
On our Xamarin Android project we are trying to switch from sqlite-net to official sqlite-net-pcl package.
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.
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
回答1:
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.
回答2:
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:
Probably there was an error in the original nuget package.
来源:https://stackoverflow.com/questions/40907410/android-the-type-initializer-for-sqlite-sqliteconnection-threw-an-exception