Bug 37402 - Xamarin Android app is not able to establish connection with Kaazing libraries in Release mode while linker option set to LinkAssembliesOnly
Summary: Xamarin Android app is not able to establish connection with Kaazing librarie...
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 6.0.99
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Radek Doulik
Depends on:
Reported: 2016-01-05 06:58 UTC by Akram
Modified: 2016-01-21 12:17 UTC (History)
1 user (show)

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

Demo to reproduce the issue (81.78 KB, application/zip)
2016-01-05 06:58 UTC, Akram

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:

Description Akram 2016-01-05 06:58:12 UTC
Created attachment 14439 [details]
Demo to reproduce the issue

We have created a simple Xamarin Android app that makes connection with Kaazing libraries to connect to Kaazing Gateway. And we set following options in the configuration:

Application Build -> Linker-> Link SDK assemblies only

The above option is applied for both Debug and Release mode.

The issue we are facing and stop us going production is that in the Release mode we are not able to make the connection to the gateway, the connection is immediately getting closed there is no any specific exception thrown that gives us some clue of what can the issue. Take note that in the *Debug Mode* we are able to to establish connection. It is happening only in release mode.

We have attached the sample of the app that connects to ws://echo.websocket.org. If We change the linker to 'Don't link' it works fine but the apk is too large , so we are guessing the linker is stripping out something that the app is needing in RELEASE mode.

Take note that we tried to ignore Kaazing.Gateway assemblies from the linker options but we still experiencing the same issue. It is getting very difficult for us to debug since there is noting in the XS logs and devices logs.

Xamarin Studio
Version 5.10.1 (build 6)
Installation UUID: aa407210-7847-499c-9f9b-61740be379bf
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

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

Apple Developer Tools
Xcode 7.1.1 (9081)
Build 7B1005

Version: (Starter Edition)
Hash: 7322991
Branch: master
Build date: 2015-12-08 16:20:29-0500

Version: (Trial Edition)
Android SDK: /Users/akramyakubov/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.1.2
SDK Platform Tools Version: 22.0.0
SDK Build Tools Version: 23 rc3

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Xamarin Android Player
Not Installed

Not Installed

Build Information
Release ID: 510010006
Git revision: 0b60eecdb531933734519c13257d16a780274aab
Build date: 2015-12-04 20:28:20-05
Xamarin addins: 9876fd7c9837977178411ec7375b4352c0a0d6af
Build lane: monodevelop-lion-cycle6-baseline

Operating System
Mac OS X 10.11.2
Darwin Akrams-MacBook-Pro.local 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:56:56 PST 2015
    root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
Comment 1 Radek Doulik 2016-01-13 19:50:48 UTC
I have checked the issue you are seeing. The reason, why it is happening, is that Kaazing.Gateway assembly is using a lot of reflection calls to load assemblies, methods, ... These are linked out and the library probably hides the reflection exceptions.

You can workaround that by adding System.dll to the list of "Ignored assemblies" in the Linker options. If the size of the apk is still too big, you might need to find out what Kaazing.Gateway assembly loads and needs thru reflection and create custom linker configuration for it. See https://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/
Comment 2 Akram 2016-01-15 17:11:01 UTC
Hi Redek,

I wonder if there is way to find out `the library probably hides the reflection exceptions` or to make it visible.
Comment 3 Radek Doulik 2016-01-21 12:17:06 UTC
I don't think there's easy way to see these. I would suggest checking the assembly in the browser to see where the reflection happens or use the cmd-line tools like ikdasm and monodis.

Or contact the assembly author to find out what he/she loads with reflection to create custom linker description, see https://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/