Xamarin.Android 10.3.0.74
Pre-releaseApril 17, 2020 — Xamarin.Android 10.3.0.74 was published to the Preview updater channel of Visual Studio 2019 for Mac version 8.6 Preview 2
April 16, 2020 — Xamarin.Android 10.3.0.74 was published as part of Visual Studio 2019 version 16.6 Preview 3
Corresponding Visual Studio 2019 Preview release notes
What's new
- Preview bindings for Android 11 Developer Preview 2
- App startup performance
- R8 configured to suppress common build errors
- XA1011 error for D8 with ProGuard
- More aggressive incremental clean of obj directory for certain scenarios
- Issues fixed
- Installing
- Open source
Preview bindings for Android 11 Developer Preview 2
This version includes preview bindings for the second Developer Preview of Android 11 from Google. See the Android 11 Developer Preview documentation for additional information about the behavior and API changes in this new Android version. To try the bindings for the new APIs in a Xamarin.Android project, set Compile using Android version: (Target Framework) to Android 10.0.99 (R) under the Application tab of the Visual Studio project property pages. This sets the TargetFrameworkVersion
property to v10.0.99
in the .csproj file:
<TargetFrameworkVersion>v10.0.99</TargetFrameworkVersion>
App startup performance
- Mono GitHub PR 19102: Use
GArray
instead ofGList
when getting custom attributes from an image. This reduces the number of memory allocations during app startup for a standard Xamarin.Forms app, which should improve startup times by several milliseconds.
R8 configured to suppress common build errors
Xamarin.Android now configures R8 to skip emitting an error for Java dependency warnings such as:
R8 : warning : Missing class: org.apache.http.client.methods.HttpEntityEnclosingRequestBase
R8 : warning : Missing class: java.lang.ClassValue
R8 : error : Compilation can't be completed because some library classes are missing.
This allows a more gradual transition to R8, particularly for projects that are using R8 for multidex only and not code shrinking.
Although R8 warnings will no longer cause the build to fail, project authors are encouraged to address the warnings at their earliest convenience and then set R8 back to its original stricter behavior. To restore the original behavior, set the AndroidR8IgnoreWarnings
MSBuild property to false
in the .csproj file:
<PropertyGroup>
<AndroidR8IgnoreWarnings>false</AndroidR8IgnoreWarnings>
</PropertyGroup>
Example: How to solve Missing class: org.apache.http.client
R8 : warning : Missing class: org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Best solution
Update any NuGet packages or Java dependencies that use the Apache HTTP client to newer versions that use java.net.HttpURLConnection
instead. This is the best solution because starting in Android 6.0 Marshmallow (API level 23), the Apache HTTP client is deprecated in favor of the more efficient HttpURLConnection
.
Second-best solution
If new library versions are not yet available that use HttpURLConnection
, then, where possible, update any NuGet packages that use Apache HTTP client to newer versions that include a UsesLibraryAttribute
for org.apache.http.legacy:
[assembly: UsesLibrary("org.apache.http.legacy", false)]
NuGet package authors who cannot yet update all dependencies to use HttpURLConnection
are encouraged to add this attribute to their projects as soon as possible.
This attribute automatically generates the following element under the <application>
node of AndroidManifest.xml for any app that references the NuGet package:
<uses-library android:name="org.apache.http.legacy" android:required="false" />
Fallback solution
If updated NuGet package versions are not yet available with the attribute, then add the same UsesLibraryAttribute
directly to the application project instead:
[assembly: UsesLibrary("org.apache.http.legacy", false)]
Background information
The Missing class: org.apache.http.client warning indicates that the app has a Java dependency on the Apache HTTP client. Starting in Android 6.0 Marshmallow (API level 23), that client was deprecated and moved out of android.jar into its own org.apache.http.legacy.jar library. As a result, applications that use Apache HTTP client on Android 6.0 or higher will only be able to call the APIs successfully if they declare the use of org.apache.http.legacy via a <uses-library>
element in AndroidManifest.xml. Otherwise, the API calls will fail with exceptions similar to:
Java.Lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/impl/client/DefaultHttpClient
Example: How to solve Missing class: java.lang.ClassValue
R8 : warning : Missing class: java.lang.ClassValue
Solution
It is typically safe to suppress this warning:
-
Add a new text file to the project, named for example proguard-rules.pro.
-
Set the contents of the file to:
-dontwarn java.lang.ClassValue
-
Edit the .csproj file in a text editor and add
--pg-conf proguard-rules.pro
to theAndroidR8ExtraArguments
MSBuild property, for example by adding the following lines:<PropertyGroup> <AndroidR8ExtraArguments>--pg-conf proguard-rules.pro</AndroidR8ExtraArguments> </PropertyGroup>
(If the project is configured to use R8 for code shrinking, an easier option is to set the Build Action of proguard-rules.pro to ProguardConfiguration in the Visual Studio Properties window, but that approach is not yet supported when using R8 for multidex only.)
Background information
The Missing class: java.lang.ClassValue warning indicates that the app references a library that uses java.lang.ClassValue
. Typically this happens when the app references a library that was built to run on multiple Java platforms. On Android, the java.lang.ClassValue
type does not exist in the java.lang package.
One known scenario that produces this warning is when an app references the Xamarin.Firebase.Firestore NuGet package, which depends on the cross-platform Google Guava library. Guava uses java.lang.ClassValue
, but it only uses it on platforms where it is available, so it is safe to suppress the Missing class: java.lang.ClassValue warning for that library.
A future version of the Xamarin.Guava.Google NuGet package will provide the -dontwarn java.lang.ClassValue
R8 rule to suppress the warning automatically. In the mean time, application authors can suppress the warning by adding the rule to their app projects directly.
XA1011 error for D8 with ProGuard
Any project using the D8 DEX compiler that has either Code shrinker (AndroidLinkTool
) set to ProGuard or the older AndroidEnableProguard
MSBuild property set to true
will now get an XA1011 build error:
error XA1011: Using ProGuard with the D8 DEX compiler is no longer supported. Please update `$(AndroidLinkTool)` to `r8`.
In the past, this configuration was allowed, but now only the R8 code shrinker is supported for use with the D8 DEX compiler.
To resolve this error, update the Code shrinker setting in the Visual Studio project property pages to r8. This corresponds to the r8
value for the AndroidLinkTool
MSBuild property in the .csproj file:
<PropertyGroup>
<AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>
Note: R8 might in some cases produce new build warnings or errors compared to ProGuard, so the ProGuard rules for the project might require updates after this change.
More aggressive incremental clean of obj directory for certain scenarios
In previous versions, Xamarin.Android reserved a costlier, more complete incremental clean of the intermediate output directory for special scenarios where a NuGet package changed or where the AndroidPackageNamingPolicy
MSBuild property changed. Xamarin.Android 10.3 expands this behavior to cover several other MSBuild properties:
AndroidAotMode
AndroidCreatePackagePerAbi
AndroidDexTool
AndroidEmbedProfilers
AndroidEnableProfiledAot
AndroidExplicitCrunch
AndroidGenerateJniMarshalMethods
AndroidIncludeDebugSymbols
AndroidLinkMode
AndroidLinkSkip
AndroidLinkTool
AndroidNdkDirectory
AndroidPackageFormat
AndroidSdkBuildToolsVersion
AndroidSdkDirectory
AndroidSequencePointsMode
AndroidUseLatestPlatformSdk
AndroidUseSharedRuntime
AotAssemblies
BundleAssemblies
EmbedAssembliesIntoApk
JavaSdkDirectory
MonoSymbolArchive
OS
TargetFrameworkVersion
XamarinAndroidVersion
This should reduce the number of cases where project authors need to run a full clean by hand after changing one of these properties, such as after updating to a new Xamarin.Android version.
Changes to these particular properties already triggered additional build steps, so this new behavior should not noticeably increase incremental build times. As in the past, to get the best incremental build times, avoid changing these properties back and forth too much between builds.
Issues fixed
Application and library build and deployment
- GitHub PR 4382 Starting in Xamarin.Android 10.3.0.33, noisy and redundant errors from jarsigner.jar and apksigner.jar were shown if the
AndroidKeyStore
MSBuild property wastrue
and theAndroidSigningKeyStore
property was set to a file that did not exist. - GitHub 4409: ; expected prevented using comma-delimited lists in
Aliases
MSBuild item metadata on Xamarin.Android library project references. - GitHub PR 4422: error APT0001: unknown option... was inaccurate for cases where an option was misspelled, and it did not yet mention the relevant property MSBuild properties.
- GitHub PR 4444: System.IO.IOException: The directory is not empty could sometimes prevent the
RemoveDirFixed
task from removing temporary build directories. The task now produces a warning instead, allowing the build to complete successfully. - GitHub 4478, GitHub 4486: On macOS, starting in Xamarin.Android 10.2, [INSTALL_FAILED_INVALID_APK: ... base.apk code is missing] and Module 'base' has no dex files prevented deploying successfully for certain projects configured to use the DX DEX compiler.
Application behavior on device and emulator
- GitHub 4415: Starting in Xamarin.Android 10.2.100.7, System.NotSupportedException: Cannot create instance of type ... no Java peer type found caused certain apps to crash during launch after incremental deployments.
Application Mono Framework behavior on device and emulator
This version of Xamarin.Android updates the Mono 6.12 runtime and class libraries from Commit d90665a4 to Commit 165f4b03, adding 19 new commits.
Fixes included for issues reported with Xamarin.Android applications:
- Mono GitHub 18917: Explicit implementations of interface properties were ignored if the interfaces provided default implementations.
Installing
To get the new version in Visual Studio, update Visual Studio:
- Visual Studio 2019 version 16.6 Preview 3 — Visual Studio Installer
- Visual Studio 2019 for Mac version 8.6 Preview 2 — Visual Studio for Mac Installer with the Preview updater channel
For other scenarios, the latest commercial .vsix and .pkg installer packages can be found in the project README.
Open source
Xamarin.Android 10.3 is based on the open-source Xamarin.Android repositories:
- The Mono runtime and class library artifacts for this version come from the android-release-Darwin-*.7z archive generated by the Mono open-source build: archive-mono/job/2020-02 build #66.
- Core JNI interaction logic is in the Java.Interop repo.
- Android bindings and MSBuild tooling are in the xamarin-android repo.
- Chat is in the
xamarin/xamarin-android
Gitter channel.