Xamarin.Android 7.4

Xamarin.Android 7.4: Something something fixes?

OSS Core

Xamarin.Android 7.0 is the first release to use the open-source repositories:

System Requirements

Xamarin.Android 7.4 requires JDK 1.8 to use the Android Nougat (API 24) APIs. Using the Android build-tools r24+ package may also require using JDK 1.8. You can continue to use earlier versions of the JDK when using earlier build-tools packages and when targeting earlier Android API levels:

Additionally, a 64-bit version of the JDK is required to use custom controls in the Android designer.

The simplest option is to install the 64-bit version of JDK 1.8 since it is backwards compatible with all of the previous API levels and supports the new Android designer features.

Vulkan Support

Android v7.0 Nougat adds support for the Vulkan API. Vulkan support will not be distributed as part of the core Xamarin.Android binding. Instead, please use the VulkanSharp NuGet package, and the XLogo sample app.

Native Library Use

Due to a change by Google, Android N will now only permit linking to NDK-provided native libraries. libsqlite.so is not an NDK-provided native library. Consequently, existing apps using e.g. Mono.Data.Sqlite.dll will crash when running on Android N. This may include other SQLite-using assemblies, not distributed with Xamarin.Android.

Xamarin.Android 7.0 updated Mono.Data.Sqlite.dll to include a custom built version of libsqlite.so, named libsqlite3_xamarin.so.

All Developers need to audit their code for P/Invoke and ensure that referenced native libraries are either included in the Android NDK, or are included within the app.apk itself. The only Xamarin.Android-provided assembly impacted by this change is Mono.Data.Sqlite.dll.

Known Issues

Xamarin.Android changed the default GC Bridge from old to tarjan.

Unfortunately, a few bugs have been reported which suggest a bug within the Tarjan GC bridge.

If this happens, create an @(AndroidEnvironment) file and add the following line:

MONO_GC_PARAMS=bridge-implementation=old

This will cause the app to use the previous GC bridge.

Xamarin.Android 7.4

The Xamarin.Android 7.4 release primarily includes bug fixes.

New Features

  • Beuller?

Experimental Features

Xamarin.Android 7.3 retains the experimental features from previous releases:

TLS 1.2 support in WebRequest

Xamarin.Android 7.1 added AndroidClientHandler, which uses the native Java APIs to provide TLS 1.2 support. However, there are two problems with AndroidClientHandler:

  1. It can only be used with HttpClient, and
  2. It requires Android 5.0 and later to operate. (Prior Android versions might not support TLS 1.2, and since AndroidClientHandler uses the native Java TLS stack...)

To solve these problems, Boring SSL can be used as the lowest-level TLS implementation. Originally announced last September, Boring SSL can be embedded within a Xamarin.Android application, allowing HttpWebRequest to communicate with TLS 1.2 endpoints. When enabled, the normal HttpClient stack also uses Boring SSL.

To enable use of BoringSSL, add the $(AndroidTlsProvider) MSBuild property to the application project, with a value of btls:

<PropertyGroup>
  <AndroidTlsProvider>btls</AndroidTlsProvider>
</PropertyGroup>

When enabled, a new libmono-btls-shared.so shared library will be present within the .apk.

The default value of the $(AndroidTlsProvider) MSBuild property is the empty string, i.e. not set, which will use the managed TLS implementation, which does not support TLS 1.2.

The default value may change in a future release.

Concurrent GC Support

The new $(AndroidEnableSGenConcurrent) MSBuild property which controls whether or not the concurrent GC is enabled.

$(AndroidEnableSGenConcurrent) is a boolean value. When True, then Mono's GC is set to marksweep-conc; when False, then Mono's GC is set to marksweep.

The default value is False.

See Mono's ConcurrentSGen documentation for more information.

Improved Fast Deployment

Fast Deployment is a way to avoid rebuilding and redeploying Android Packages (.apk files) when assemblies have changed in a way that doesn’t require changing the generated Android Callable Wrappers or altered any included Android Assets and Resources.

Xamarin.Android 7.0 will optionally allow Android Assets, Resources, and compiled Java libraries to particpate in fast deployment as well, further reducing the number of situations in which a possibly slow .apk rebuild and redeploy will be required.

This new behavior is disabled by default. It will be enabled by default in the Xamarin.Android 7.1 series.

To enable this new functionality, set the $(AndroidFastDeploymentType) MSBuild property to Assemblies:Dexes:

<AndroidFastDeploymentType>Assemblies:Dexes</AndroidFastDeploymentType>

Adding Resources to the Default Project

For example, assume a new (default) Application project which has already been deployed to a target device.

  1. Copy Resources\layout\Main.axml to Resources\layout\Another.axml, and add Resources\layout\Another.axml to the project.
  2. Run the project.

(2) will require that the .apk be rebuilt and re-deployed to the target. In previous versions, (2) could take 16 seconds.

With the new system

TODO:

Add some small benchmarks about what happens during dev when code changes, or a resource changes, numbers before/after

File name and line number information in release builds

File name and line number information in Release builds is supported through the build-time generation of .pdb files (and .msym files for AOT builds). The generation of the sequence points is controlled by the new $(MonoSymbolArchive) MSBuild property, which must be set to True to enable generation:

<MonoSymbolArchive>True</MonoSymbolArchive>

You also need to set $(DebugSymbols) to True and $(Optimize) to True for your release build. This will ensure that your assemblies do not contain debug information but that the required data is stored in the .pdb/.mSYM files.

When enabled, a new $(OutputPath)\@PACKAGE_NAME@.mSYM directory will be created which contains all information required to correlate IL offset information (found in stack traces) back to file name and line number information through the use of the mono-symbolicate tool.

Next, grab a crash log which an unhandled exception

adb logcat -d > errors.txt

Finally, use mono-symbolicate to convert the errors to contain file and line numbers:

mono-symbolicate path-to-dll-in-.mSYM-directory path-to-errors.txt

mono-symbolicate can be found at:

  • macOS: /Library/Frameworks/Xamarin.Android.framework/Commands/mono-symbolicate
  • Windows: %ProgramFiles(x86)%\MSBuild\Xamarin\Android\mono-symbolicate.exe

For example, given an errors.txt with the contents:

I/MonoDroid( 1545): System.Exception: wow it broke
I/MonoDroid( 1545):   at CrashApp.MainActivity+<OnCreate>c__AnonStorey0.<>m__0 (System.Object , System.EventArgs ) [0x00030] in <filename unknown>:0
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x00014] in <filename unknown>:0
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00011] in <filename unknown>:0
I/MonoDroid( 1545):   at (wrapper dynamic-method) System.Object:5616285d-461b-4005-a31b-d4637a8cdddc (intptr,intptr,intptr)

mono-symbolicate will translate the above into:

I/MonoDroid( 1545): System.Exception: wow it broke
I/MonoDroid( 1545):   at CrashApp.MainActivity+<OnCreate>c__AnonStorey0.<>m__0 (System.Object , System.EventArgs ) [0x00030] in /Users/dean/Projects/CrashApp/CrashApp/MainActivity.cs:30
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x00014] in /Users/dean/Documents/Sandbox/Xamarin/dellismonodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Webkit.WebBackForwardList.cs:68
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00011] in /Users/dean/Documents/Sandbox/Xamarin/dellismonodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Webkit.WebBackForwardList.cs:23
I/MonoDroid( 1545):   at (wrapper dynamic-method) System.Object:5616285d-461b-4005-a31b-d4637a8cdddc (intptr,intptr,intptr)

Notice that the <filename unknown>:0 messages were translated into appropriate filename and line number information.

Breaking Changes

There are some deprecations and removals in Xamarin.Android 7.4.

API-10 is Obsolete

Google Play Services deprecated support for API-10 Android "Gingerbread" v2.3.x in February, 2017. The June 2017 release of Google Play Services has removed support for Gingerbread.

Xamarin.Android is following suit: Xamarin.Android 7.4 is the last version that will include an API-10 binding assembly for Mono.Android.dll, with a $(TargetFrameworkVersion) of v2.3. Developers should migrate their projects to use a later $(TargetFrameworkVersion) value.

FSharp.Core.dll has been removed

Many years ago, when Mono for Android was new, the easiest way to support F# was for the Xamarin team to compile FSharp.Core.dll from source, so that it would be built against the correct mscorlib.dll and other dependencies.

That is no longer the case. The FSharp.Core NuGet package has shipped Xamarin.Android compatible assemblies since at least 3.0.2, released in 2014. There is thus no need for Xamarin.Android to provide an FSharp.Core.dll assembly: the Xamarin team is not actively following the F# community, doesn't know when the F# team will have a new release, and is not able to distribute a new F# release in a fast and reliable manner.

Use the NuGet package.

This is also the core of Bug #41262: F# projects should use the FSharp.Core NuGet package.

Additionally, in the Xamarin.Android 7.1 timeframe, the IDEs were updated so that new projects defaulted to using the NuGet package.

I was perfectly happy with a world in which Xamarin.Android continued distributing an ancient FSharp.Core.dll assembly (v3.x!). Existing projects would continue to build, and if newer F# features were required, the FSharp.Core NuGet package was available.

Unfortunately, due to not-entirely-understood build system changes, the FSharp.Core.dll distributed with Xamarin.Android is now being used in preference to the NuGet package, through no changes on the Xamarin.Android side of things. This means that the NuGet package cannot be used, which is a very unfortunate state of affairs.

The Xamarin.Android 7.4 release no longer distributes the FSharp.Core.dll assembly. Please update your projects to use the NuGet package.

Bug Fixes

  • 12935: sensorPortrait should be sensorPortait
  • 32861: [Smoke] ProGuard fails with "error ... (Access is denied)" if Android SDK path contains a space
  • 33052: The option for multi-dex fails when the path to the Android SDK contains a space
  • 38693: Call of mainDexClasses.bat does not produce records in multidex.keep
  • 55305: AndroidClientHandler ignores timeout value when trying to connect on misconfigured networks.
  • 55477: Stream Closed Exception thrown in AndroidClientHandler during redirected HTTP POST call.
  • 56537: InetAddress.HostAddress is empty for IPv4 addresses on Nougat
  • 56653: Zygote crashes
  • 56808: Cannot debug referenced iOS Class library in Visual Studio 2015/2017
  • 56815: HAVELARGEFILE_SUPPORT broken on monodroid/master w/ mono/2017-04
  • 56864: [VS 2017 XA Self Hosted VSIX] Getting exception "System.ArgumentNullException: Value cannot be null" when deploying android App
  • 56867: [VS 2017 XA Self Hosted VSIX] Xamarin.Android version is not displayed in "help > About Microsoft Visual studio"
  • 56966: Unable to Run Cheesesquare app in Release mode on HTC One X
  • 56976: F# is missing __ANDROID__ define (regression)
  • 57027: Follow-up to Bug 33052: "Invalid option" causes java.exe failure during build with multidex if username contains spaces

Integrated Mono Features/Fixes

Xamarin.Android uses Mono 5.2 commit 30e73d4.

  • 580: Type.Load loads strong type despite version mismatch
  • 39444: Action ReflectedType differs from Delegate ReflectedType for virutal methods
  • 40969: HttpListener does not work with IPV6
  • 43805: Output of DateTime.Now() differs on Mono for ambiguous time period
  • 43988: Stack overflow in System.Text.Encoding.Default
  • 46661: Runtime exception filters truncate exception stack traces on NSLog
  • 46929: Datetime error on Mono.data.Sqlite
  • 47221: Thread.Name can only be set once inside async callback
  • 47599: HttpClient Transfer-Encoding:chunked is not added to the header - not able to transfer large files
  • 49721: Assembly binder uses wrong strongly named assembly when same assembly with different version exists in local folder
  • 51522: Overload resolution fails for referenced assembly
  • 51561: Getting process name of process running under higher privilege user throws exception
  • 51653: monothreadinfowaitone_handle ignored alertable argument
  • 52086: Nullable structs with implicit operators generate invalid IL code when compiling with Mono
  • 52294: C# compiler reports an incorrect error in a lambda with generic constraints
  • 52340: Compiler crashes with FATAL UNHANDLED EXCEPTION (nullref)
  • 52345: Process has exited, so the requested information is not available
  • 52429: Shutdown hang then crash in Finalizer thread
  • 52437: Random NullReferenceExceptions in StringBuilder.ThreadSafeCopy
  • 52448: StreamContent apparently needs to rewind stream before sending it
  • 52475: MTOUCH: error MT3001: Could not AOT the assembly
  • 52508: TLS SignalR Self-host Hang
  • 52511: configure script doen't detect bad configuration
  • 52549: error: monow32socketconvert_error: no translation into winsock error for (41) "Protocol wrong type for socket"
  • 52590: Cannot compile for iOS, TypeBuilder exists in two places.
  • 52599: await in finally clause prevents disposal of enclosing using statement
  • 52600: Full AOT: Strange combination of structs, generics, and enums causes runtime failure
  • 52795: Infinite loop on MySqlDataReader.ReadAsync() causing 100% CPU usage - regression
  • 52845: [Cycle 9] Satellite assemblies not bundled when using "Bundle assemblies into native code" due to "unknown escape sequence" error from gcc during mkbundle step
  • 52866: F# sprintf AOT bug still exists
  • 52899: mprof-report missing filenames in coverage xml output when using portable pdbs
  • 53066: Can't Build Project in Debug with "Could not AOT the assembly"
  • 53131: Calling MakeArray() on a type with a rank that is too big does not throw an exception.
  • 53153: Implement RuntimeHelpers::IsReferenceOrContainsReferences
  • 53166: Application crashes when setting a get-only property in constructor
  • 53196: List<>.Sort() using insertion sort does not sort all values when equality isn't checked.
  • 53202: Number minus Enum gives wrong value
  • 53278: Two coreclr SIMD test failures (one regression from 4.8)
  • 53334: es-US Culture wrong number formatting
  • 53684: Crash when enumerating directory and selecting the first file
  • 53689: [Test] Certificate7 disabled due to SecCertificateCreateWithData does different things on 10.11 vs 10.12 with invalid certificates
  • 53792: CFNetworkHandler reports correct download when internet connection is lost during request
  • 53843: Mono deadlocks on shutdown while waiting for a process which has died
  • 53890: Regression: Native crash while running tests with xunit with mono 2017-02 branch, works with 4.8.0.520
  • 54212: Mono allows casts of non-zero bound array to zero bound array
  • 54322: await in catch-block inside a loop causes the same exception to be caught multiple times
  • 54448: Unable to revert to thread-local storage for CurrentThread.CultureInfo
  • 54485: Creating an open generic type with recurrent constraint fails
  • 54991: Cannot compile get => _text
  • 55041: Stripping mscorlib in simple example changes IntPtr (5) behavior?
  • 55083: coreclr test b353858.il fails after 6f33b62f39a273fccb78f71513cb5e0dfb987c70
  • 55148: Debugger checks type which is possibly never used
  • 55577: SIMD instructions with System.Numerics.Vectors do not work
  • 55603: Follow-up to bug 52845: Satellite assemblies not loaded by app when using "Bundle assemblies into native code" even though they are now successfully mkbundled
  • 55681: System.Reflection.Emit.ModuleBuilder.build_metadata bug when running FAKE's test suite
  • 56081: Returning a valuetype from an async method with an awaited parameter yields a Mono.CSharp.InternalErrorException: Await yields with non-empty stack
  • 56247: Enumerable.OrderByDescending behaves differently on LLVM FullAOT
  • 56493: Windows MMAP doesn't release file
  • 56499: DateTime.Now throws exception if /etc/localtime symlink destination missing
  • 56567: Passing large struct into exception filter method crashes runtime with SIGSEGV
  • 56611: Regression: ArrayTypeMismatchException when running F# script
  • 56694: Assertion: should not be reached at d:\j\workspace\v\repos\mono\mono\sgen\sgen-scan-object.h:91
  • 56821: Static ctor of MarshalByRefObject runs in primary AppDomain
  • 56824: Runtime crash with VSMEF
  • 57222: System.Reflection.AmbiguousMatchException for two fields with same name but different types

API Changes

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.