Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Latest commit

 

History

History
186 lines (141 loc) · 8.2 KB

install-android-support-library.md

File metadata and controls

186 lines (141 loc) · 8.2 KB
title description ms.topic ms.service ms.assetid ms.subservice author ms.author ms.date
How can I manually install the Android Support libraries required by the Xamarin.Android.Support packages?
Download the desired Xamarin.Android.Support NuGet package (for example by installing it with the NuGet package manager).
troubleshooting
xamarin
A9CB8CA8-8A6D-405E-B84C-A16CE452C0F7
xamarin-android
davidortinau
daortin
02/16/2018

How can I manually install the Android Support libraries required by the Xamarin.Android.Support packages?

Example steps for Xamarin.Android.Support.v4

Download the desired Xamarin.Android.Support NuGet package (for example by installing it with the NuGet package manager).

Use ildasm to check which version of android_m2repository.zip the NuGet package needs:

ildasm /caverbal /text /item:Xamarin.Android.Support.v4 packages\Xamarin.Android.Support.v4.23.4.0.1\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll | findstr SourceUrl

Example output:

property string 'SourceUrl' = string('https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip')
property string 'SourceUrl' = string('https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip')
property string 'SourceUrl' = string('https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip')

Download android_m2repository.zip from Google using the URL returned from ildasm. Alternately, you can check which version of the Android Support Repository you currently have installed in the Android SDK Manager:

"Android SDK Manager showing Android Support Repository version 32 installed"

If the version matches the one you need for the NuGet package, then you don't have to download anything new. You can instead re-zip the existing m2repository directory that is located under extras\android in the SDK Path (as shown the top of the Android SDK Manager window).

Calculate the MD5 hash of the URL returned from ildasm. Format the resulting string to use all uppercase letters and no spaces. For example, adjust the $url variable as needed and then run the following 2 lines (based on the original C# code from Xamarin.Android) in PowerShell:

$url = "https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip"
(([System.Security.Cryptography.MD5]::Create()).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($url)) | %{ $_.ToString("X02") }) -join ""

Example output:

F16A3455987DBAE5783F058F19F7FCDF

Copy android_m2repository.zip into the %LOCALAPPDATA%\Xamarin\zips\ folder. Rename the file to use the MD5 hash from the previous MD5 hash calculating step. For example:

%LOCALAPPDATA%\Xamarin\zips\F16A3455987DBAE5783F058F19F7FCDF.zip

(Optional) Unzip the file into %LOCALAPPDATA%\Xamarin\Xamarin.Android.Support.v4\23.4.0.0\content\ (creating a content\m2repository subdirectory). If you skip this step, then the first build that uses the library will take a little longer because it will need to complete this step. The version number for the subdirectory (23.4.0.0 in this example) is not quite the same as the NuGet package version. You can use ildasm to find the correct version number:

ildasm /caverbal /text /item:Xamarin.Android.Support.v4 packages\Xamarin.Android.Support.v4.23.4.0.1\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll | findstr /C:"string 'Version'"

Example output:

property string 'Version' = string('23.4.0.0')}
property string 'Version' = string('23.4.0.0')}
property string 'Version' = string('23.4.0.0')}

Download the desired Xamarin.Android.Support NuGet package (for example by installing it with the NuGet package manager).

Double-click the Xamarin.Android.Support.v4 assembly under the References section of the Android project in Visual Studio for Mac to open the assembly in the Assembly Browser. Ensure that the Language drop-down is set to C# and select the top-level Xamarin.Android.Support.v4 assembly from the Assembly Browser navigation tree. Locate the SourceUrl property under one of the IncludeAndroidResourcesFrom or JavaLibraryReference attributes:

[assembly: IncludeAndroidResourcesFrom ("./", PackageName = "Xamarin.Android.Support.v4", SourceUrl = "https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip", EmbeddedArchive = "m2repository/com/android/support/support-v4/23.4.0/support-v4-23.4.0.aar", Version = "23.4.0.0")]

Download android_m2repository.zip from Google using the SourceUrl returned from ildasm. Alternately, you can check which version of the Android Support Repository you currently have installed in the Android SDK Manager:

"Android SDK Manager showing Android Support Repository version 32 installed"

If the version matches the one you need for the NuGet package, then you don't have to download anything new. You can instead re-zip the existing m2repository directory that is located under extras/android in the SDK Path (as shown the top of the Android SDK Manager window).

Calculate the MD5 hash of the URL returned from ildasm. Format the resulting string to use all uppercase letters and no spaces. For example, adjust the URL string as needed and then run the following command in a Terminal.app command prompt:

echo -n "https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip" | md5 | tr '[:lower:]' '[:upper:]'

Another option is to use the csharp interpreter to run the same C# code that Xamarin.Android itself uses. To do that, adjust the url variable as needed and then run the following command in a Terminal.app command prompt:

csharp -e 'var url = "https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip"; string.Concat((System.Security.Cryptography.MD5.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(url))).Select(b => b.ToString("X02")))'

Example output:

F16A3455987DBAE5783F058F19F7FCDF

Copy android_m2repository.zip to the $HOME/.local/share/Xamarin/zips/ folder. Rename the file to use the MD5 hash from the previous MD5 hash calculating step. For example:

$HOME/.local/share/Xamarin/zips/F16A3455987DBAE5783F058F19F7FCDF.zip

(Optional) Unzip the file into:

$HOME/.local/share/Xamarin/Xamarin.Android.Support.v4/23.4.0.0/content/

(creating a content/m2repository subdirectory). If you skip this step, then the first build that uses the library will take a little longer because it will need to complete this step.

The version number for the subdirectory (23.4.0.0 in this example) is not quite the same as the NuGet package version. As in the ildasm step earlier, you can use the Assembly Browser in Visual Studio for Mac to find the correct version number. Look for the Version property under one of the IncludeAndroidResourcesFrom or JavaLibraryReference attributes:

[assembly: IncludeAndroidResourcesFrom ("./", PackageName = "Xamarin.Android.Support.v4", SourceUrl = "https://dl-ssl.google.com/android/repository/android_m2repository_r32.zip", EmbeddedArchive = "m2repository/com/android/support/support-v4/23.4.0/support-v4-23.4.0.aar", Version = "23.4.0.0")]

Next Steps

This document discusses the current behavior as of August 2016. The technique described in this document is not part of the stable testing suite for Xamarin, so it could break in the future.

For further assistance, to contact us, or if this issue remains even after utilizing the above information, please see What support options are available for Xamarin? for information on contact options, suggestions, as well as how to file a new bug if needed.