Xamarin.Android 7.5

Xamarin.Android 7.5: Something something more fixes?

OSS Core

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

System Requirements

Xamarin.Android 7.5 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.

A preview binding for Android API-26 is distributed. In the initial Alpha release, the API is API incompatible with API-25 and prior releases, which causes all manner of breakage when using the Designer or any pre-existing library. This will be fixed in a future release. For now, Please set $(AndroidUseLatestPlatformSdk) to False and explicitly choose a $(TargetFrameworkVersion) value.

Xamarin.Android 7.5

The Xamarin.Android 7.5 release primarily includes bug fixes.

New Features

  • Beuller?

Experimental Features

Xamarin.Android 7.5 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.

Bug Fixes

  • 33052: The option for multi-dex fails when the path to the Android SDK contains a space
  • 55477: Stream Closed Exception thrown in AndroidClientHandler during redirected HTTP POST call.
  • 55561: "Processing" messages spam Android build output
  • 56655: Debugging on a new device doesn't deploy
  • 56966: Unable to Run Cheesesquare app in Release mode on HTC One X
  • 57027: "Invalid option" causes java.exe failure during build with multidex if username contains spaces
  • 57692: Encountering build error when android-26/android.jar is installed and AndroidUseLatestPlatformSdk is true
  • 58178: macOS installer on High Sierra will fail if javac is not available

Integrated Mono Features/Fixes

Xamarin.Android uses Mono 5.2 commit 3d531ba6.

  • 57744 - ReflectionTypeLoadException.LoaderExceptions has null exceptions / [reflection] Convert correct MonoError to an exn in Assembly.GetTypes ()

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.