Xamarin.Android 9.1.103.12
Pre-releaseXamarin.Android 9.1.103.12 was released as part of Visual Studio 2019 Preview 3.
What's New
- Temporary Breakage for Apps That Use
AppDomain.GetAssemblies()
, Including Xamarin.Forms Apps with CSS - App Startup Performance Improvements
- Mono.Data.Sqlite SQLite Version Update to 3.26.0
- Incompatibility with Minimum Android Versions below Android 2.3 (API level 9)
- Issues Fixed
Temporary Breakage for Apps That Use AppDomain.GetAssemblies()
, Including Xamarin.Forms Apps with CSS
Due to an application startup performance improvement that stops preloading all assemblies during startup, the behavior of AppDomain.GetAssemblies()
has changed in this preview. This will become an opt-in behavior in the next Xamarin.Android 9.2 preview, but in Xamarin.Android 9.1.103.12, there is not yet a way to prevent the new behavior, so this change will disrupt applications that rely on the old behavior.
C# code using System.Reflection
and AppDomain.GetAssemblies()
may be affected such as:
- Dependency injection libraries
- Certain Xamarin.Forms features
- Potentially other mobile frameworks (MVVM, etc.) that leverage
System.Reflection
A workaround to explicitly call Assembly.Load()
at startup may be needed.
Xamarin.Forms apps that use CSS style sheets are one important scenario affected by this change:
-
Xamarin.Forms GitHub 5164: Xamarin.Forms apps that use CSS style sheets and do not have XAML Compilation enabled fail with a
NullReferenceException
atXamarin.Forms.Xaml.ApplyPropertiesVisitor.ProvideValue()
during application startup on device or emulator.Temporary workaround: Add a call to
System.Reflection.Assembly.Load("Xamarin.Forms.Xaml")
as the first statement in theActivity.OnCreate(Bundle bundle)
override in the Android app project:// In your MainActivity.cs, or first activity protected override void OnCreate(Bundle bundle) { // Workaround, to manually load Xamarin.Forms.Xaml before Xamarin.Forms startup Assembly.Load("Xamarin.Forms.Xaml"); base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); }
This workaround will no longer be necessary in the next Xamarin.Android 9.2 preview version.
App Startup Performance Improvements
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.
Mono.Data.Sqlite SQLite Version Update to 3.26.0
The version of SQLite used by Mono.Data.Sqlite in Xamarin.Android has been updated to 3.26.0, bringing in additional improvements and bug fixes compared to the Xamarin.Android 9.2 preview.
Incompatibility with Minimum Android Versions below Android 2.3 (API level 9)
Xamarin.Android projects configured to use a minimum Android version below Android 2.3 (API level 9) will fail to build with the following error:
error: method init in class Runtime cannot be applied to given types;
Runtime.init (
required: String,String[],String,String[],ClassLoader,String[],String[],String,int,String[]
found: String,String[],String,String[],ClassLoader,String[],String[],String
reason: actual and formal argument lists differ in length
The recommended way to resolve this error is to update the minimum API level to Android 2.3 (API level 9) or higher. This value can be found in the project properties under Android Manifest > Minimum Android version in Visual Studio and under Android Application > Minimum Android version in Visual Studio for Mac.
The error appears because the app startup performance improvements in this release expose an obsolete code path for these older API levels.
Issues Fixed
Application and Library Build Process
- GitHub PR 2647: The
Aapt2Link
task left behind some temporary files after builds of projects configured to use AAPT2.
Application Behavior on Device and Emulator
- 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 totrue
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.
Application Mono Framework Behavior on Device and Emulator
This version of Xamarin.Android updates the Mono 5.18 runtime and class libraries from Commit 23f2024a to Commit 725ba2a2, adding 29 new commits.
A couple changes relevant to Xamarin.Android are:
- GitHub PR 11828: Fix race condition in
XmlCharType.Instance
- GitHub PR 12410: Fix debugger crash when there is a generic
struct
with a field that is an enumerator
Design-Time Build Process
- GitHub 2548: In Visual Studio 2019 Preview 2, the
_ResolveAssemblies
build target could fail during design-time builds triggered by the Android designer, leading to errors in the Android designer. - GitHub PR 2607: In Visual Studio 2019 Preview 2, the
ResolveLibraryProjectImports
task was not always returning full paths for the output items. This could cause errors when working with the Android designer.