Compartilhar via


Xamarin.Android 9.2 release notes

System requirements | What's new | Blogs | Open source

Installing

What's new in Xamarin.Android 9.2

Xamarin.Android 9.2 releases

Corresponding Visual Studio 2019 release notes

April 18, 2019 — Xamarin.Android 9.2.3.0

This version is included in the Visual Studio 2019 version 16.0.3 release and in the Stable updater channel of Visual Studio 2019 for Mac.

Issues fixed in Xamarin.Android 9.2.3.0

Application Mono Framework behavior on device and emulator

This version of Xamarin.Android updates the Mono 5.18 runtime and class libraries from Commit 5ad371da, to Commit 5ac37ccd, adding 2 new commits:

  • Developer Community 435502, Developer Community 515603, GitHub 2920: Xamarin.Android apps would crash during debugging when they called certain APIs. Applications affected by this issue would run successfully if launched without the debugger attached, but when launched with the debugger attached, the applications would exit unexpectedly after one of the problematic APIs was called. The debug output would show a "Fatal signal 11 (SIGSEGV)" after the crash.
  • Mono GitHub 13610: Xamarin.Android projects in which users had explicitly set a value for the undocumented, experimental $(AndroidAotMode) MSBuild property could hit a problem where methods that returned Task objects or generic types would lead to incorrect return values. This is not expected to be an issue for any current Xamarin.Android projects. The fix is included in this release to keep the Mono commit aligned with Xamarin.iOS.

April 2, 2019 — Xamarin.Android 9.2.0.5

This version is included in the Visual Studio 2019 and Visual Studio 2019 for Mac releases.

Summary of what's new in Xamarin.Android 9.2.0.5

Build and deployment performance improvements

This release includes several more improvements to build and deployment times compared to Visual Studio 2017 version 15.9. For example, in a test development environment, the incremental build time after modifying one XAML page in the SmartHotel360 sample app has dropped from 8.5 seconds to 7.5 seconds and the corresponding deployment time has dropped from 5 seconds to 4.5 seconds.

See also:

  • The Build Performance Results page on the project wiki for additional comparisons and updates about the on-going work to continue to improve performance.
  • The latest numbers from the continuous integration builds.

Specific improvements

  • GitHub PR 2088: Adjust the _CopyIntermediateAssemblies target to replace a couple uses of the Copy task with CopyIfChanged and avoid calling the Touch task. This improved the incremental build time for a test project from roughly 7 seconds to roughly 6.5 seconds.
  • GitHub PR 2124: Add conditions and correct item wildcards for the _CreateAapt2VersionCache target to improve build times in projects configured to use AAPT2.
  • GitHub PR 2129: Split part of the ConvertResourcesCases task into a new ConvertCustomView task to avoid repeating work later in the build. This saves roughly half the time spent in the ConvertResourcesCases task, which can be several seconds or more for an initial clean build.
  • GitHub PR 2148: Properly dispose AssemblyDefinition instances during the BuildApk task. This improved the overall build time for a test project by about 5%.
  • GitHub PR 2162: Move the StripEmbeddedLibraries task to be a linker step to save one pass of loading the assemblies for writing and to avoid redundant work on assemblies that the linker would skip. This improved the combined time of stripping and linking for a test project in the Release configuration from 16.1 seconds to 15.4 seconds.
  • GitHub PR 2168: Remove some redundant work the ResolveAssemblies build task was doing when iterating through assembly metadata.
  • GitHub PR 2174: Combine the CheckTargetFrameworks task into the ResolveAssemblies task to save one pass of reading through assembly metadata.
  • GitHub PR 2223: Optimize the default $(AssemblySearchPaths) and $(AllowedReferenceAssemblyFileExtensions) MSBuild properties by removing locations and extension types that are never used for Xamarin.Android projects. This improved the incremental build time by approximately 0.5 seconds for a test project that references 7 other Xamarin.Android projects.
  • GitHub PR 2308, GitHub PR 2320, GitHub PR 2326: Correct how several targets handle and update the timestamps of their Outputs. This prevents some scenarios where incremental builds could get stuck in a state where they would always rebuild the affected targets.
  • GitHub PR 2309: Remove unused Inputs and Outputs from several targets. This improved the total build time for those targets in a test project by a few dozen milliseconds.
  • GitHub PR 2328: Add the RegexOptions.Compiled option to a Regex and change some LINQ expressions to loops in the ConvertResourcesCases task. This improved the total time for the task in a test project by a few hundred milliseconds.
  • GitHub PR 2348: Allow the ConvertResourcesCases task to skip a specific set of "well-known" assemblies by name. For example, after this change, ConvertResourcesCases now skips all of the Xamarin.Android.Support, Xamarin.GooglePlayServices, and Xamarin.Firebase assemblies because those assemblies are built by the Xamarin team and never contain resource names that need to be converted. This can save 1 second or more for both initial clean builds and incremental builds after resource changes. The time saved depends on how many of these assemblies are used by the project.
  • GitHub PR 2384: Adjust the ResolveSdks task to cache the detected location of the JVM. This improved the incremental build time for a test project by a few hundred milliseconds.
  • GitHub PR 2394: Improve the incremental build behavior of the _ConvertPdbFiles, _CopyPdbFiles, and _CopyMdbFiles targets by correcting the Outputs so the timestamps are only updated if the contents have changed and by fixing an issue where duplicate copies of items were being added to @(FileWrites) on each build.
  • GitHub PR 2428: Save the $(AdbTarget) and $(AdbOptions) MSBuild properties in their own file rather than in the build.props file to prevent the deployment process from re-running unnecessary build targets when the deployment target has just been changed from emulator to device or from one device to another.
  • GitHub PR 2487: Change the LinkAssemblies task so that it checks for .mdb files with File.Exists() before it tries to access them. This avoids some exception handling overhead, reducing the total time for the task by a couple dozen milliseconds.
  • GitHub PR 2535: Adjust the GenerateJavaStubs and GenerateResourceDesigner tasks to perform generation and comparison in-memory rather than in temporary files, and make a few additional efficiency improvements in the GenerateJavaStubs task. This improved the initial clean build time for a test project by a few hundred milliseconds.
  • GitHub PR 2540: Adjust the ResolveLibraryProjectImports task to avoid allocating an intermediate byte[] and to avoid generating intermediate temporary files. This improved the total time for the task by a few dozen milliseconds.

App startup performance improvements

  • GitHub PR 1886, GitHub PR 2147: Avoid unnecessary string allocations during app startup. This reduced the time for the GetJavaToManagedType() startup step in a test application from 10 milliseconds to 1 millisecond.

  • GitHub PR 2008, GitHub PR 2126: Use a faster approach to register managed methods with the Android runtime during app startup. This reduced the method registration time in a test application from 56 milliseconds to 18 milliseconds in the Release configuration and from 169 milliseconds to 33 milliseconds in the Debug configuration.

  • GitHub PR 2025: Slightly reduce the overhead of setting up managed method overrides and callback methods for types in or subclassed from Java bindings.

  • GitHub PR 2473: Avoid allocating or evaluating unused arguments in the primitive logging functions. This can reduce application startup time by a couple dozen milliseconds, depending on the target device.

  • GitHub PR 2500: Skip attempting to load the Java.Interop.Export.dll assembly during app startup because that part of the Java.Interop library is not used by Xamarin.Android. This can reduce application startup time by roughly 100 milliseconds, depending on the target device.

  • GitHub PR 2515: Optimize several application startup operations:

    • Reduce Java class lookup.
    • Don't lookup android.os.Build.VERSION.SDK_INT via JNI.
    • jstring handling improvements.
    • Review logging messages.
    • Improve package name hash generation.
    • Improve environment variable processing.
    • Stop preloading all assemblies.
    • Avoid using "system properties" to control Mono features.
    • Desktop version is now a compile-time build option, not runtime.
    • Initialize xamarin_getifaddrs() on-demand, not at startup.

    These optimizations reduced the average startup time for a test application from 0.7 seconds to 0.3 seconds in the Release configuration and from 1.4 seconds to 1.1 seconds in the Debug configuration.

    These optimizations are all enabled by default except for the change to stop assembly preloading. Skipping assembly preloading can cause exceptions for C# code that uses System.Reflection and AppDomain.GetAssemblies() and doesn't yet explicitly call Assembly.Load(). Current versions of certain libraries could be affected, including:

    • Dependency injection libraries
    • Certain Xamarin.Forms features
    • Potentially other mobile frameworks (MVVM, etc.) that leverage System.Reflection

    In the future, after Xamarin.Forms and other libraries have been updated for compatibility, Xamarin.Android release will likely change the default behavior to skip preloading the assemblies. If your app is already compatible with skipping the preload step, you can can apply the extra startup time improvement by setting the $(AndroidEnablePreloadAssemblies) MSBuild property to false in your .csproj file:

    <PropertyGroup>
        <AndroidEnablePreloadAssemblies>false</AndroidEnablePreloadAssemblies>
    </PropertyGroup>
    

Support for Android's D8 DEX compiler

The March 2018 release of the Android SDK introduced a new DEX compiler D8 that improves both compile times and app performance compared to the previous compiler DX. Xamarin.Android 9.2 updates the Xamarin.Android build tasks to be compatible with D8. Because D8 is not yet widely used by Xamarin.Android projects, it is not yet enabled by default. To try it with your project, set the $(AndroidDexTool) MSBuild property to d8 in your .csproj file:

<PropertyGroup>
    <AndroidDexTool>d8</AndroidDexTool>
</PropertyGroup>

For additional details about D8 in the context of Xamarin.Android, including a few comparisons of build speeds and sizes, see the integration specification notes.

Support for Android's R8 code shrinker

Recent versions of the Android SDK also include a preview of a new code shrinker R8 that aims to produce smaller DEX files more quickly than ProGuard. Xamarin.Android does not yet enable R8 by default. To try it with your project, set the $(AndroidLinkTool) MSBuild property to r8 in your .csproj file:

<PropertyGroup>
    <AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>

For additional details about R8 in the context of Xamarin.Android, including a few comparisons of build speeds and sizes, see the integration specification notes.

Known issues

  • GitHub 2684: Xamarin.Android apps built with R8 enabled are currently only compatible with devices running Android 8.0 Oreo (API level 26) or higher. On earlier Android versions, apps built with R8 enabled will get stuck in an infinite error loop during app initialization and never show the first layout.

Enhanced fast deployment

Fast deployment has historically provided faster incremental deployment times by skipping rebuilding or redeploying the Android package (APK) when there have been no changes to the AndroidManifest.xml file or to any assets, resources, shared native libraries packaged within the app, or user-defined classes that inherit from Java.Lang.Object.

Xamarin.Android 9.2 enhances fast deployment so that it now supports most of those previously unsupported scenarios except for changes to the AndroidManifest.xml file. For example, adding a new Android layout file or a new user-defined class that inherits from Java.Lang.Object now no longer require the APK to be rebuilt or redeployed.

This new enhanced fast deployment mode is not yet enabled by default because it has a few known issues. But it is already compatible with a number of scenarios, so if you would like to try it with your project, set the $(AndroidFastDeploymentType) MSBuild property to Assemblies:Dexes in your .csproj file:

<PropertyGroup>
    <AndroidFastDeploymentType>Assemblies:Dexes</AndroidFastDeploymentType>
</PropertyGroup>

For any users who might have tried the earlier experimental version of this feature introduced in Xamarin.Android 7.0, note that at the moment this new version still has an incompatibility with custom Android.App.Application subclasses, but it does add new capabilities that allow fast deployment of both shared native libraries as well as classes that inherit from Java.Lang.Object.

Known issues

Support for android:extractNativeLibs="false"

Android 6.0 (API level 23) introduced a new way to handle native shared libraries that are packaged as part of APKs. Before that API level, the libraries would always be extracted and placed in the application data directory, consuming extra space on the file system. API level 23 added a new manifest <application> element attribute android:extractNativeLibs to control whether the native libraries are extracted during installation. If the attribute is set to false, then Android 6.0 and higher will skip the extraction step and attempt to load the libraries directly from the APK instead.

Xamarin.Android 9.2 adds compatibility support for this functionality. At the moment, enabling this mode requires a few manual steps:

  • Add the android:extractNativeLibs="false" attribute to the <application> element in the Properties\AndroidManifest.xml file

  • Set the $(AndroidStoreUncompressedFileExtensions) MSBuild property to .so in your .csproj file:

    <PropertyGroup>
        <AndroidStoreUncompressedFileExtensions>.so</AndroidStoreUncompressedFileExtensions>
    </PropertyGroup>
    
  • Add an android environment file to the project with the following contents:

    __XA_DSO_IN_APK=1
    

Mono Framework version update to 5.18

This version of Xamarin.Android updates the Mono runtime and class libraries from Mono 5.14 to Mono 5.18 Commit 5ad371da, Mono 5.18 resolves several issues in the runtime and base class libraries and imports more CoreFX implementations for types in the System.Reflection and System.Math namespaces.

Mono.Data.Sqlite SQLite version update

The version of SQLite used by Mono.Data.Sqlite in Xamarin.Android has been updated from 3.9.2 to 3.26.0, bringing in many improvements and bug fixes.

Deprecation of OpenTK version 0.9.9.3

The assembly for OpenTK version 0.9.9.3 will be removed from Xamarin.Android in an upcoming release. Xamarin.Android has for several years included assemblies for both OpenTK version 0.9.9.3 and OpenTK version 1.0.0.0 to allow a gradual transition to version 1.0.0.0. It is now time to finalize that transition by removing the old version from Xamarin.Android. Any projects that have not yet switched from OpenTK version 0.9.9.3 (OpenTK.dll) should now be updated to remove that old reference and add a reference to OpenTK version 1.0.0.0 (OpenTK-1.0.dll) instead.

In Visual Studio the selected reference for OpenTK should now be:

Visual Studio Reference Manager with OpenTK version 1.0.0.0 selected

And in Visual Studio for Mac the selected reference should now be:

Visual Studio for Mac Edit References window with OpenTK version 1.0.0.0 selected

Removal of target framework versions below Android 4.4 (API level 19)

As cautioned by the related build warning that was added in the Xamarin.Android 9.1 release (see GitHub PR 2329), Xamarin.Android 9.2 removes support for the v2.3, v4.0.3, v4.1, v4.2, and v4.3 values of the $(TargetFrameworkVersion) MSBuild property. Projects that have one of these old target framework versions selected will now need to change it to v4.4 or higher. The $(TargetFrameworkVersion) setting can be found in the Application section of the project properties in Visual Studio and the Build > General section of the project properties in Visual Studio for Mac.

Projects that have an old target framework selected will see the following build error until $(TargetFrameworkVersion) has been updated:

error XA0001: Unsupported or invalid $(TargetFrameworkVersion) value of 'v4.1'. Please update your Project Options.

Note that applications built against a target framework version of Android 4.4 (API level 19) or higher can still be deployed and run successfully on devices that are using Android 4.3 (API level 18) or lower. For more information, see the section about runtime checks in the guide on Android API levels.

Removal of support for armeabi CPU architecture

Due to the removal of armeabi support in Android NDK r17, Xamarin.Android 9.2 no longer supports the armeabi architecture. Projects that have this old ABI selected in the $(AndroidSupportedAbis) MSBuild property will now need to remove it. The newer armeabi-v7a ABI should be used instead. The $(AndroidSupportedAbis) setting can be found in the Advanced section of the Android Options project properties in Visual Studio and the Advanced tab of the Android Build project properties in Visual Studio for Mac. The armeabi option is no longer listed in that properties page, so one way to ensure that the old setting has been removed is to un-check and re-check one of the other options and then save the project properties.

Projects that have the old ABI selected will see the following build error until $(AndroidSupportedAbis) has been updated:

error XA0115: Invalid value 'armeabi' in $(AndroidSupportedAbis). This ABI is no longer supported. Please update your project properties.

Issues fixed

Application and library build process

  • GitHub 1879: Using version 4.5.0 or higher of the System.Threading.Tasks.Extensions NuGet package could lead to compile errors about missing types from that library. Xamarin.Android now includes a System.Threading.Tasks.Extensions.dll facade assembly that provides the appropriate type forwarders for those types.
  • GitHub 2029, GitHub 2218: Build errors could potentially occur in projects configured to use AAPT2 if they also referenced NuGet packages that provided custom values for the $(AndroidResgenExtraArgs) MSBuild property.
  • GitHub PR 2108: The built-in list of types, methods, and fields to preserve when linking mscorlib.dll included some redundant and outdated items.
  • GitHub PR 2117: A few build tasks were generating warnings or errors that did not include numbered codes.
  • GitHub 2141: App deployment could fail due to an "INSTALL_FAILED_CONFLICTING_PROVIDER" error when using certain recent Android libraries such as Crashlytics that contain their own AndroidManifest.xml file.
  • GitHub 2143: The Desugar build task did not pass the --classpath_entry option to desugar_deploy.jar, resulting in build errors about missing types when desugaring certain .jar files.
  • GitHub PR 2150: The ConvertResourcesCases and CopyAndConvertResources build tasks contained redundant try/catch blocks.
  • GitHub PR 2187: The CompileToDalvik build task was passing individual input item names on the command line to dx.jar instead of combining the names into a file and using the --input-list option. This could potentially cause issues with command line length limitations in cases where many inputs were given.
  • GitHub 2200: Builds could hit a new error in Xamarin.Android 9.1 instead of automatically using the default detected location as expected in projects that had a nonexistent custom path explicitly set in the $(AndroidSdkDirectory) MSBuild property.
  • GitHub PR 2251: If the ResolveLibraryProjectImports task encountered corrupt data, it would fail with an error similar to "error MSB4018: The "ResolveLibraryProjectImports" task failed unexpectedly ... Xamarin.Tools.Zip.ZipIOException" rather than a more instructive error.
  • GitHub 2356: The ConvertResourcesCases task was running many times during builds of projects configured to use AAPT2.
  • GitHub 2360, GitHub 2361, GitHub 2362, GitHub 2363: Various lint errors could appear because the _LintChecks target was passing the whole $(IntermediateOutputPath) MSBuild property to lint. This caused lint to check files from all referenced pre-built libraries in addition to the files from the current build. The _LintChecks target now only passes the files from the current build.
  • GitHub PR 2483: Build errors about missing resources could occur in application projects configured to use AAPT2 if any of the layout files used uppercase letters in a reference to a resource from a library project.
  • GitHub 2534: Using the Microsoft.EntityFrameworkCore version 2.2.0 NuGet package led to a build error during the _ResolveAssemblies target with the message "error XA2002: Can not resolve reference: System.Buffers, referenced by System.Memory." Xamarin.Android now includes built-in System.Memory.dll and System.Buffers facade assemblies, and the _ResolveAssemblies target completes successfully.
  • GitHub PR 2647: The Aapt2Link task left behind some temporary files after builds of projects configured to use AAPT2.
  • GitHub 2692: The build tasks and targets did not yet provide a warning for projects that have the minimum Android version set lower than Android 2.3 (API level 9). This warning is needed because the native parts of Xamarin.Android are built against Android NDK r14, so Xamarin.Android apps might not work correctly on devices running Android versions older than Android 2.3 (API level 9).
  • GitHub 2708: Projects that used Bundle assemblies into native code or AOT Compilation (Experimental) would fail to build with different error messages if the Android NDK could not be found. Neither message mentioned how to resolve the problem. Both scenarios now produce the same message that includes steps to resolve the error by installing the NDK or setting the $(AndroidNdkDirectory) MSBuild property.

Application behavior on device and emulator

  • GitHub 1615: AndroidClientHandler did not provide TLS 1.1 or TLS 1.2 support on Android versions 4.1 to 4.4.
  • GitHub 1673: Attempting to run large APKs on device or emulator could fail on startup if the size of the APK exceeded the largest available contiguous block of free memory. In Xamarin.Android 9.2, the app startup process now calls mmap() separately for individual files from the APK instead of once for the whole APK. This allows larger APKs to run successfully.
  • GitHub 2081: Applications with the android:directBootAware attribute set to true for the whole application or for an activity, content provider, broadcast receiver, or service would quit unexpectedly when attempting to launch on a freshly rebooted, locked device running Android 7.0 Nougat or higher.
  • GitHub 2123: AndroidClientHandler did not yet support HTTP proxy server configuration.
  • GitHub PR 2192: Apps could fail to run on Android 6.0 (API level 23) devices if built with Bundle assemblies into native code enabled.
  • GitHub 2193: Building, adding a new view to a .axml layout file, and then deploying an application could lead to an "Android.Views.InflateException... Attempt to invoke virtual method on a null object reference" error when running the app because the layout file updates were not deployed as expected.
  • GitHub 2202: The [IntentFilter] attribute was being ignored on classes decorated with a [ContentProvider] attribute.
  • GitHub PR 2480: Android assets located within subdirectories were missing from APKs in projects configured to use AAPT2 when building on Windows to due an upstream issue in aapt2. The Xamarin.Android build tasks now fix up the output from aapt2 to work around this issue.

Android API bindings

  • Developer Community 399276: Android.Hardware.Biometrics.BiometricErrorCode was incorrectly bound as BiometricsErrorCode instead of BiometricErrorCode, resulting in a missing binding for Android.Hardware.Biometrics.BiometricPrompt.AuthenticationCallback.OnAuthenticationError(). Both types are now bound correctly.
  • GitHub 1891: The [Android.App.Activity] attribute did not include properties for all of the XML attributes for which Android Studio offers autocompletion in AndroidManifest.xml <activity/> elements. The list of properties has now been updated to include the missing items.

Design-time build process

  • Developer Community 335298: Binding projects that used .aar files could cause IntelliSense errors similar to "error CS0234: The type or namespace name ... does not exist in the namespace ... (are you missing an assembly reference?)" to appear in the consuming application projects.
  • GitHub 2410: The ValidateJavaVersion task was being run during design-time builds when it did not need to run, decreasing the responsiveness of working interactively in Visual Studio.

Feedback welcome

Your feedback is important to us. If there are any problems with this release, check our GitHub Issues, Xamarin.Android Community Forums and Visual Studio Developer Community for existing issues. For new issues within the Xamarin.Android SDK, please report a GitHub Issue. For general Xamarin.Android experience issues, let us know via the Report a Problem option found in your favorite IDE under Help > Report a Problem.

Contributors

A big Thank You! to contributors who made improvements in this release:

OSS core

Xamarin.Android 9.2 is based on the open-source Xamarin.Android repositories: