Bug 48620 - System.DllNotFounException : e_sqlite3, unless packages referenced by library are included in main app project
Summary: System.DllNotFounException : e_sqlite3, unless packages referenced by library...
Status: RESOLVED ANSWERED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 7.0 (C8)
Hardware: Macintosh Mac OS
: Highest normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2016-12-01 19:56 UTC by ulrike_axen
Modified: 2017-03-17 11:53 UTC (History)
2 users (show)

Tags: XATriaged
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project that displays the error when an override to Application is included (44.49 KB, application/zip)
2016-12-01 19:56 UTC, ulrike_axen
Details
Application Output when dll exception occurs (75.22 KB, text/plain)
2017-01-03 17:18 UTC, ulrike_axen
Details
Application output when e_sqlite3 load succeeds (60.26 KB, text/plain)
2017-01-03 17:18 UTC, ulrike_axen
Details
screenshot in debug mode when Couchbase files moved to main app project (51.19 KB, image/png)
2017-01-03 21:26 UTC, ulrike_axen
Details
Updated test project (45.16 KB, application/zip)
2017-02-07 14:45 UTC, ulrike_axen
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description ulrike_axen 2016-12-01 19:56:30 UTC
Created attachment 18743 [details]
Test Project that displays the error when an override to Application is included

We use Couchbase Lite. I'm trying to make it work targeting Android N, and I get this run-time error if my app includes an override of Application (our app does). If I remove the override of Application, it works. I will upload a very simple test project that exhibits the error. In the test project, restore the packages and do a Clean/Rebuild. You will see this run-time error. If you remove the source file "GlobalApplication.cs", do a clean/rebuild, no run-time error, it works.

(Another oddity: if you leave GlobalApplication.cs in the project, but remove the reference to Mono.Data.Sqlite, you will get another System.DllNotFoundException for the xamarin sqlite so in the GlobalApplication constructor
Comment 1 ulrike_axen 2016-12-01 19:56:51 UTC
=== Xamarin Studio Enterprise ===

Version 6.1.2 (build 44)
Installation UUID: 0ca42116-8f54-4ad6-bd25-aa90f20c571f
Runtime:
	Mono 4.6.2 (mono-4.6.0-branch/08fd525) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406020007

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Version: 0.20.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.1 (11544)
Build 8B62

=== Xamarin.Mac ===

Version: 2.10.0.113 (Visual Studio Enterprise)

=== Xamarin.Android ===

Version: 7.0.2.37 (Visual Studio Enterprise)
Android SDK: /Users/axenu/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 25
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: 10.2.1.5 (Visual Studio Enterprise)
Hash: 44931ae
Branch: xcode8.1
Build date: 2016-11-01 20:52:28-0400

=== Build Information ===

Release ID: 601020044
Git revision: 0ccfcd52b95305ebd5b7eca0d88c1017035910ae
Build date: 2016-10-28 15:12:43-04
Xamarin addins: a39a869d8a78d87bdc6775f696c13a4cc9024501
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.11.6
Darwin ulrikes-mbp-2.ms.starkey.com 15.6.0 Darwin Kernel Version 15.6.0
    Thu Sep  1 15:01:16 PDT 2016
    root:xnu-3248.60.11~2/RELEASE_X86_64 x86_64
Comment 2 ulrike_axen 2016-12-01 19:58:22 UTC
Now that I've been able to isolate the problem, I will move on to seeing if there is a workaround for our main app. Removing GlobalApplication is not a realistic workaround. If you are aware of a workaround (lines of code to add?), please let me know, thanks!
Comment 3 ulrike_axen 2016-12-01 20:39:30 UTC
A co-worker reminded me we had a similar bug submitted when Android N was first in preview. We found a more simple way to "fix" this project. Simply comment out the override of OnCreate in GlobalApplication.cs, and you do not get the sqlite run-time error for the couchbase init
Comment 4 ulrike_axen 2016-12-01 21:06:03 UTC
Please note: Comment 3 does not imply that we have found a workaround! Commenting out OnCreate in our GlobalApplication.cs is not an option for us. I simply included that as a more simple way for you to make the project "work", and hopefully help you find the root cause. Thanks!
Comment 5 ulrike_axen 2016-12-07 15:33:20 UTC
I would like to request that this bug be moved to "high" priority.

The reasoning for this is:

1) It's in the stable channel.
2) There is no simple workaround. (Removing onCreate for GlobablApplication would require a refactor...)
3) It prevents us from targeting Nougat, and there are already devices shipping with Nougat.
4) At some point, Google has promised that even apps that are targeting an OS < Nougat will stop being able to link to the native sqlite.so on Nougat devices. My understanding of that is that our app will stop working at that point, unless we've released an update that links only to packaged sqlite libraries.

We would really need a solution to link to packaged sqlite libraries, thanks!

(Apparently there was not an official bug at the start of the Android N program -- we reported an issue to customer support but he suggested waiting until the next release, which resolved the issue at that time. It was similar).
Comment 6 Jon Goldberger [MSFT] 2016-12-07 23:25:06 UTC
I could not build the test project out of the box until I updated all NuGet packages. Then I got the error running on a Marshmallow simulator. 

>System.DllNotFoundException: e_sqlite3
>  at 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 <5581ba1fb87941c99cd99c8f00bddaf9>:0
>  at SQLitePCL.raw.SetProvider (SQLitePCL.ISQLite3Provider imp) [0x00000] in <f1197b4b07654d869a75a206cde261b2>:0
>  at SQLitePCL.Batteries.Init () [0x00005] in <ed3fb915ea3b4431be925261af092bb7>:0
>  at xF.Data.CouchbaseDatabase.Init () [0x0001a] in /Users/jongoldberger/Downloads/TestLinq/xF.Data/CouchbaseDatabase.cs:43
>  at TestLinq.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00048] in /Users/jongoldberger/Downloads/TestLinq/TestLinq/MainActivity.cs:27
>  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/3511/ce955cc0/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.App.Activity.cs:2550
>  at at (wrapper dynamic-method) System.Object:27161a87-8db2-4c22-9966-b07e71b142e5 (intptr,intptr,intptr)

but after getting the app to run and getting the error above, I tried removing the GlobalApplication class, but still got the same error. Also compiling against Android 6.0 made no difference on my end. 

Not sure if this is an issue with the new Android N requirements about linking non NDK provided native libs as discussed here:
https://blog.xamarin.com/preparing-for-native-library-linking-changes-in-android-n/
but I did not see a message in the DDMS as noted in the "How to test" section. 

Application output:
>[Mono] DllImport attempting to load: 'e_sqlite3'.
>[Mono] DllImport error loading library './libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3" not found'.
>[Mono] DllImport error loading library './libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'e_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/e_sqlite3" not found'.
>[Mono] DllImport error loading library './libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3" not found'.
>[Mono] DllImport error loading library './libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport unable to load library 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport attempting to load: 'e_sqlite3'.
>[Mono] DllImport error loading library './libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3" not found'.
>[Mono] DllImport error loading library './libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'e_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/e_sqlite3" not found'.
>[Mono] DllImport error loading library './libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3" not found'.
>[Mono] DllImport error loading library './libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/./libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3" not found'.
>[Mono] DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64//system/lib/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3.so" not found'.
>[Mono] DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport unable to load library 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/x86_64/libe_sqlite3" not found'.
>[Mono] DllImport attempting to load: '/system/lib64/liblog.so'.
>[Mono] DllImport loaded library '/system/lib64/liblog.so'.
>[Mono] DllImport searching in: '/system/lib64/liblog.so' ('/system/lib64/liblog.so').
>[Mono] Searching for '__android_log_print'.
>[Mono] Probing '__android_log_print'.
>[Mono] Found as '__android_log_print'.
>[MonoDroid] UNHANDLED EXCEPTION:
>[MonoDroid] System.DllNotFoundException: e_sqlite3
>[MonoDroid]   at (wrapper managed-to-native) SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods:sqlite3_libversion_number ()
>[MonoDroid]   at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number () [0x00000] in <5581ba1fb87941c99cd99c8f00bddaf9>:0 
>[MonoDroid]   at SQLitePCL.raw.SetProvider (SQLitePCL.ISQLite3Provider imp) [0x00000] in <f1197b4b07654d869a75a206cde261b2>:0 
>[MonoDroid]   at SQLitePCL.Batteries.Init () [0x00005] in <ed3fb915ea3b4431be925261af092bb7>:0 
>[MonoDroid]   at xF.Data.CouchbaseDatabase.Init () [0x0001a] in /Users/jongoldberger/Downloads/TestLinq/xF.Data/CouchbaseDatabase.cs:43 
>[MonoDroid]   at TestLinq.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00048] in /Users/jongoldberger/Downloads/TestLinq/TestLinq/MainActivity.cs:27 
>[MonoDroid]   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/3511/ce955cc0/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.App.Activity.cs:2550 
>[MonoDroid]   at (wrapper dynamic-method) System.Object:d00b1f9e-0866-40d7-aa55-60b04c194f77 (intptr,intptr,intptr)
>[art] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
>[Mono] DllImport searching in: '__Internal' ('(null)').
>[Mono] Searching for 'java_interop_jnienv_throw'.
>[Mono] Probing 'java_interop_jnienv_throw'.
>[Mono] Found as 'java_interop_jnienv_throw'.
>[mono] 
>[mono] Unhandled Exception:
>[mono] System.DllNotFoundException: e_sqlite3
>[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: e_sqlite3

Setting as confirmed as I could reproduce the issue. 

## My environment

=== Xamarin Studio Enterprise ===

Version 6.1.2 (build 44)
Installation UUID: ceaba76c-db06-4fbd-b326-f69ea53c3e01
Runtime:
	Mono 4.6.2 (mono-4.6.0-branch/08fd525) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406020007

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Version: 0.33.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 7.0.2.37 (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)
		7.0   (API level 24)

SDK Tools Version: 25.2.3
SDK Platform Tools Version: 25.0.1
SDK Build Tools Version: 24.0.3

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 8.1 (11544)
Build 8B62

=== Xamarin.Mac ===

Version: 2.10.0.113 (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: 10.2.1.5 (Visual Studio Enterprise)
Hash: 44931ae
Branch: xcode8.1
Build date: 2016-11-01 20:52:28-0400

=== Xamarin Inspector ===

Version: 0.10.0.0
Hash: e931a52
Branch: master
Build date: Thu, 18 Aug 2016 17:46:46 GMT

=== Build Information ===

Release ID: 601020044
Git revision: 0ccfcd52b95305ebd5b7eca0d88c1017035910ae
Build date: 2016-10-28 15:12:43-04
Xamarin addins: a39a869d8a78d87bdc6775f696c13a4cc9024501
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.12.1
Darwin Jons-MacBook-Pro.local 16.1.0 Darwin Kernel Version 16.1.0
    Thu Oct 13 21:26:57 PDT 2016
    root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector 0.10.0.0
Comment 7 ulrike_axen 2016-12-08 13:21:30 UTC
Thanks for verifying Jon! The difference in our results after removing GlobalApplication may be due to different test devices. I was running on a Google Pixel XL (Nougat).
Comment 8 Atsushi Eno 2016-12-08 19:56:03 UTC
My wild guess is that it is not a bug but no type in the assembly that contains native library (SQLitePCLRaw.lib.e_sqlite3) is referenced in the data library and hence the entire assembly is ignored when extracting the embedded native libraries. MSBuild tasks like ResolveReferences or CreateNativeLibraryArchive would be related.
Comment 9 ulrike_axen 2016-12-08 20:09:56 UTC
Keep in mind comment 1: I did get this to run successfully with a simple test application that did not have any of the references indicated in comment 8. I was able to make my simple test project "break" when I added GlobalApplication.cs
Comment 10 ulrike_axen 2017-01-03 15:16:12 UTC
I installed the latest Xamarin updates, and was still able to reproduce this with the simple project. Can the priority of this please be moved up? It is preventing us from moving to Android N. 

Again, to reproduce simply where the issue is: in the test project, if the onCreate method has an override, e.g.:

public class GlobalApplication : Application
public override void OnCreate ()
		{
			base.OnCreate ();
	

		}


then the exception is thrown. If you comment out the override of OnCreate, then couch base is initialized without exceptions.
Comment 11 ulrike_axen 2017-01-03 15:16:57 UTC
Reproduced with:

=== Xamarin Studio Enterprise ===

Version 6.1.3 (build 19)
Installation UUID: 0ca42116-8f54-4ad6-bd25-aa90f20c571f
Runtime:
	Mono 4.6.2 (mono-4.6.0-branch/ac9e222) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406020016

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Version: 0.20.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.2.1 (11766.1)
Build 8C1002

=== Xamarin.iOS ===

Version: 10.3.1.7 (Visual Studio Enterprise)
Hash: 8b53676
Branch: cycle8-xi
Build date: 2016-12-18 12:23:27-0500

=== Xamarin.Mac ===

Version: 2.10.0.120 (Visual Studio Enterprise)

=== Xamarin.Android ===

Version: 7.0.2.42 (Visual Studio Enterprise)
Android SDK: /Users/axenu/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 25
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Not Installed

=== Build Information ===

Release ID: 601030019
Git revision: 7fabf9293c2d7b638e28a07f798d21799da1f886
Build date: 2016-12-21 07:08:35-05
Xamarin addins: efbae0e683a0060d2230e91e70c1598abc054845
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.11.6
Darwin ulrikes-mbp-2.ms.starkey.com 15.6.0 Darwin Kernel Version 15.6.0
    Wed Nov  2 20:30:56 PDT 2016
    root:xnu-3248.60.11.1.2~2/RELEASE_X86_64 x86_64
Comment 12 ulrike_axen 2017-01-03 17:18:10 UTC
Created attachment 19073 [details]
Application Output when dll exception occurs
Comment 13 ulrike_axen 2017-01-03 17:18:49 UTC
Created attachment 19074 [details]
Application output when e_sqlite3 load succeeds
Comment 14 ulrike_axen 2017-01-03 17:24:41 UTC
In attempting to find a workaround to this bug, I examined differences in the build output and packaging output between the two scenarios, and could not find any differences that would explain the outcomes.

When examining the run-time output (Application output), there was a big difference that started with the following in the Application output when the exception occurs:

[Mono] DllImport attempting to load: 'libsqlite3_xamarin.so'.
[Mono] DllImport error loading library '/storage/emulated/0/Android/data/com.starkey.testlinq/files/.__override__/libsqlite3_xamarin.so': 'dlopen failed: library "/data/app/com.starkey.testlinq-1/lib/arm64//storage/emulated/0/Android/data/com.starkey.testlinq/files/.__override__/libsqlite3_xamarin.so" not found'.


I've attached Application output for both scenarios. It appears that when we override OnCreate, the system is trying to find 'libsqlite3_xamarin.so', which is not available when targeting Nougat.
Comment 15 ulrike_axen 2017-01-03 21:26:04 UTC
Created attachment 19077 [details]
screenshot in debug mode when Couchbase files moved to main app project
Comment 16 ulrike_axen 2017-01-03 21:31:40 UTC
More information: my testing so far was in "Debug" mode, so all the prior comments are for that. In Release mode, the test app crashed with the DLLNotFoundException in any case, not related to whether or not GlobalApplication has "OnCreate".

So, in digging further, I moved my couchbase client classes out of the library project and into the main app (TestLinq project), and then added all the packages to the main app project. I unloaded the library project entirely. In that case, I did not get the DLLNotFoundException in either Debug or Release build modes. The only issue remaining was that I received an alert (I uploaded a screenshot) when in Debug mode. This alert did not display in Release mode.
Comment 17 ulrike_axen 2017-02-01 15:30:27 UTC
The answer in this SO post supports my observation, but would be a better workaround for us, as it only requires that we add the packages to the main app, not all the library code:

http://stackoverflow.com/questions/40907410/android-the-type-initializer-for-sqlite-sqliteconnection-threw-an-exception

I have tried it out in the test project I submitted, and it works. However, this is a workaround, or at least, a new requirement with Android N. There is no prior documentation that we need to include packages anywhere other than in the library project that uses them.

Is this a new requirement with the Sqlite so changes in Android N? If so, can this be documented? If not, will this be fixed?

thanks!
Comment 18 ulrike_axen 2017-02-07 14:45:13 UTC
Created attachment 19749 [details]
Updated test project

Uploading an updated test project. There are two bugs that still that this test project exhibits:

1. DLLNotFoundException: We have a workaround for the DllNotFoundException. We need to include the Couchbase and SqLite packages in the main app, even though only the library references them. The bug is that the packages referenced by a project library need to be included in the main app project.

2. Target Android Version -- Automatic does not target Api 24 (even though we have that platform installed). We have to choose "Override" to actually target Api 24.

Current Xamarin:

=== Xamarin Studio Enterprise ===

Version 6.1.5 (build 0)
Installation UUID: 0ca42116-8f54-4ad6-bd25-aa90f20c571f
Runtime:
	Mono 4.6.2 (mono-4.6.0-branch/ac9e222) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406020016

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Version: 0.20.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 7.0.2.42 (Visual Studio Enterprise)
Android SDK: /Users/axenu/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.3
SDK Build Tools Version: 24

Java SDK: /usr
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Not Installed

=== Apple Developer Tools ===

Xcode 8.2.1 (11766.1)
Build 8C1002

=== Xamarin.iOS ===

Version: 10.3.1.8 (Visual Studio Enterprise)
Hash: 7beaef4
Branch: cycle8-xi
Build date: 2016-12-20 02:58:14-0500

=== Xamarin.Mac ===

Version: 2.10.0.120 (Visual Studio Enterprise)

=== Build Information ===

Release ID: 601050000
Git revision: 7494718e127af9eaec45a3bd6282d3da927488bd
Build date: 2017-01-17 10:31:01-05
Xamarin addins: c92d0626d347aaa02839689eaac2961d24c9f446
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.11.6
Darwin ulrikes-mbp-2.ms.starkey.com 15.6.0 Darwin Kernel Version 15.6.0
    Wed Nov  2 20:30:56 PDT 2016
    root:xnu-3248.60.11.1.2~2/RELEASE_X86_64 x86_64
Comment 19 dean.ellis 2017-03-16 20:02:13 UTC
I just tried this on the latest stable release of Xamarin.Android on Mac

Version: 7.1.0.43 (Xamarin Studio Community).

The only package that I needed to reference from the main app is Couchbase.Lite.Storage.SystemSQLite. This makes sense because Couchbase.Lite has no hard references to that package or assembly. So if we don't reference it that assembly will never make it into the app.

The good news is that none of the Sqlite packages were required for the main app. Those only came from the referenced library.
Comment 20 dean.ellis 2017-03-17 10:00:58 UTC
So it seem that xf.Data in the test app (the library) directly references the package Couchbase.Lite.Storage.SystemSQLite and copies the dll to the output folder. But looking at the actual references in xf.Data is does not have any code which references Couchbase.Lite.Storage.SystemSQLite at all. As a result Mono.Cecil which is used to resolve the assemblies in the app has no way of knowing it needs that assembly. Because there are no types used from it. 

Loading xf.Data in a IL viewer shows it has no references to Couchbase.Lite.Storage.SystemSQLite. So I'm not entirely sure what we can do in this instance. I see two options.

1) Reference some code from Couchbase.Lite.Storage.SystemSQLite in xf.Dasta to force a reference.
2) Just add Couchbase.Lite.Storage.SystemSQLite to the app as a package as mentioned in Comment 19. 

@jonp do you have any other ideas?
Comment 21 dean.ellis 2017-03-17 10:23:37 UTC
I just checked the apk generated using the latest stable and libesqlite.so is in there

unzip -lv bin/Release/com.starkey.testlinq-Signed.apk 
Archive:  bin/Release/com.starkey.testlinq-Signed.apk
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
    5088  Defl:N     2098  59% 03-17-2017 10:14 e7abacc5  META-INF/MANIFEST.MF
    5209  Defl:N     2174  58% 03-17-2017 10:14 e15bae4b  META-INF/ANDROIDD.SF
    1209  Defl:N     1058  13% 03-17-2017 10:14 c5ecd563  META-INF/ANDROIDD.RSA
    2416  Defl:N      882  64% 01-01-1980 01:00 e3736f53  AndroidManifest.xml
     552  Defl:N      267  52% 01-01-1980 01:00 b0a37bc8  res/layout/main.xml
    2318  Stored     2318   0% 01-01-1980 01:00 a944159c  res/mipmap-hdpi-v4/icon.png
    1440  Stored     1440   0% 01-01-1980 01:00 6259ec2f  res/mipmap-mdpi-v4/icon.png
    4119  Stored     4119   0% 01-01-1980 01:00 ad26d6ac  res/mipmap-xhdpi-v4/icon.png
    7429  Stored     7429   0% 01-01-1980 01:00 765d2fe3  res/mipmap-xxhdpi-v4/icon.png
   11011  Stored    11011   0% 01-01-1980 01:00 8e41b6b0  res/mipmap-xxxhdpi-v4/icon.png
    1700  Stored     1700   0% 01-01-1980 01:00 cdc862b1  resources.arsc
     157  Defl:N      121  23% 03-17-2017 10:14 9574b68a  NOTICE
  316592  Defl:N    68833  78% 03-17-2017 10:14 0bd5135d  classes.dex
    6144  Stored     6144   0% 03-17-2017 10:14 39c91b7c  assemblies/TestLinq.dll
  134656  Stored   134656   0% 03-17-2017 10:14 bfa76069  assemblies/Couchbase.Lite.Storage.SystemSQLite.dll
   11264  Stored    11264   0% 03-17-2017 10:14 a854ddcd  assemblies/xF.Data.dll
   55808  Stored    55808   0% 03-17-2017 10:14 e14dc1e8  assemblies/SQLitePCL.raw.dll
  492032  Stored   492032   0% 03-17-2017 10:14 3848cc78  assemblies/Couchbase.Lite.dll
   35328  Stored    35328   0% 03-17-2017 10:14 4fe40aed  assemblies/Stateless.dll
  407552  Stored   407552   0% 03-17-2017 10:14 15562a2a  assemblies/Newtonsoft.Json.dll
  232448  Stored   232448   0% 03-17-2017 10:14 e22d044e  assemblies/websocket-sharp.dll
  183808  Stored   183808   0% 03-17-2017 10:14 c3bb7b91  assemblies/ICSharpCode.SharpZipLib.Portable.dll
   14848  Stored    14848   0% 03-17-2017 10:14 5cf15510  assemblies/System.Net.Http.WebRequest.dll
   17920  Stored    17920   0% 03-17-2017 10:14 8b736d5b  assemblies/SQLitePCL.ugly.dll
    4608  Stored     4608   0% 03-17-2017 10:14 e0da2f2e  assemblies/SQLitePCL.batteries.dll
 1871360  Stored  1871360   0% 03-17-2017 10:14 37e83fc6  assemblies/SQLitePCLPlugin_esqlite3.dll
 2228736  Stored  2228736   0% 03-17-2017 10:14 8f4dcd34  assemblies/System.dll
 2566144  Stored  2566144   0% 03-17-2017 10:14 c0b3b333  assemblies/System.Xml.dll
  942080  Stored   942080   0% 03-17-2017 10:14 d45ab0f8  assemblies/System.Core.dll
24602624  Stored 24602624   0% 03-17-2017 10:14 5b161541  assemblies/Mono.Android.dll
  133632  Stored   133632   0% 03-17-2017 10:14 5389bcfd  assemblies/System.Xml.Linq.dll
 1633280  Stored  1633280   0% 03-17-2017 10:14 b2fc1e31  assemblies/System.Data.dll
  117760  Stored   117760   0% 03-17-2017 10:14 848ef13e  assemblies/Java.Interop.dll
   13312  Stored    13312   0% 03-17-2017 10:14 5736c52e  assemblies/System.Runtime.dll
 3724800  Stored  3724800   0% 03-17-2017 10:14 199d4b4c  assemblies/mscorlib.dll
  124416  Stored   124416   0% 03-17-2017 10:14 8a36df3c  assemblies/System.Net.Http.dll
  888320  Stored   888320   0% 03-17-2017 10:14 df2cb065  assemblies/System.Runtime.Serialization.dll
  227840  Stored   227840   0% 03-17-2017 10:14 a324e8e6  assemblies/System.ServiceModel.Internals.dll
  107008  Stored   107008   0% 03-17-2017 10:14 b29e9862  assemblies/System.Numerics.dll
  104448  Stored   104448   0% 03-17-2017 10:14 f073641a  assemblies/Mono.Data.Tds.dll
   32256  Stored    32256   0% 03-17-2017 10:14 7f023583  assemblies/System.Transactions.dll
    5632  Stored     5632   0% 03-17-2017 10:14 44389bdc  assemblies/System.Threading.dll
    5120  Stored     5120   0% 03-17-2017 10:14 a27cffd0  assemblies/System.Collections.dll
    5120  Stored     5120   0% 03-17-2017 10:14 a0e98d76  assemblies/System.Collections.Concurrent.dll
    4608  Stored     4608   0% 03-17-2017 10:14 2477ddde  assemblies/System.Diagnostics.Debug.dll
    5632  Stored     5632   0% 03-17-2017 10:14 f23d43c7  assemblies/System.Reflection.dll
    4096  Stored     4096   0% 03-17-2017 10:14 f541a862  assemblies/System.Linq.dll
    7680  Stored     7680   0% 03-17-2017 10:14 6ef45877  assemblies/System.Runtime.InteropServices.dll
    5120  Stored     5120   0% 03-17-2017 10:14 b7ea4dcc  assemblies/System.Runtime.Extensions.dll
    4608  Stored     4608   0% 03-17-2017 10:14 5471eb0d  assemblies/System.Reflection.Extensions.dll
  270848  Stored   270848   0% 03-17-2017 10:14 c9428b81  assemblies/System.ComponentModel.Composition.dll
    4608  Stored     4608   0% 03-17-2017 10:14 ff25df1f  assemblies/System.IO.dll
    5120  Stored     5120   0% 03-17-2017 10:14 77a13dd5  assemblies/System.Text.Encoding.dll
    4608  Stored     4608   0% 03-17-2017 10:14 28c2d477  assemblies/System.Text.RegularExpressions.dll
     191  Defl:N      164  14% 03-17-2017 10:14 2f060b4b  environment
  144836  Defl:N    56873  61% 03-17-2017 10:14 201352a7  lib/armeabi-v7a/libmonodroid.so
 3441108  Defl:N  1485390  57% 03-17-2017 10:14 17099bf9  lib/armeabi-v7a/libmonosgen-2.0.so
  165340  Defl:N    59570  64% 03-17-2017 10:14 c099b67e  lib/x86/libmonodroid.so
 3379488  Defl:N  1351481  60% 03-17-2017 10:14 5ad908db  lib/x86/libmonosgen-2.0.so
  480252  Defl:N   325698  32% 03-17-2017 10:14 1cdebae1  lib/armeabi-v7a/libesqlite3.so
  762704  Defl:N   380966  50% 03-17-2017 10:14 dbbf30c8  lib/x86/libesqlite3.so
  791616  Defl:N   391855  51% 03-17-2017 10:14 a4493d40  lib/x86_64/libesqlite3.so
 1410619  Stored  1410619   0% 03-17-2017 10:14 c7741a09  typemap.jm
 1648699  Stored  1648699   0% 03-17-2017 10:14 235e83a2  typemap.mj
--------          -------  ---                            -------
53831325         48461997  10%                            64 files
Comment 22 dean.ellis 2017-03-17 11:53:37 UTC
I'm going to mark this as answered. x-a seems to be doing what it is supposed to be at this point with the latest stable release.