Skip to content

Commit

Permalink
[xaprepare] Support arm64 emulator components (dotnet#7743)
Browse files Browse the repository at this point in the history
Updates xaprepare to install arm64 versions of Android emulator
components on Apple devices that support them.  The `emulator` tool
version has also been bumped from `31.3.1` to `32.1.9`.
  • Loading branch information
pjcollins authored Jan 26, 2023
1 parent 586e7e5 commit f04671a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<HostOS Condition="$([MSBuild]::IsOSPlatform('windows'))">Windows</HostOS>
<HostOS Condition="$([MSBuild]::IsOSPlatform('linux'))">Linux</HostOS>
<HostOS Condition="$([MSBuild]::IsOSPlatform('osx'))">Darwin</HostOS>
<HostOSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString())</HostOSArchitecture>
</PropertyGroup>
<PropertyGroup>
<MicrosoftAndroidSdkPackName Condition="$([MSBuild]::IsOSPlatform('windows'))">Microsoft.Android.Sdk.Windows</MicrosoftAndroidSdkPackName>
Expand Down Expand Up @@ -194,9 +195,9 @@
<CommandLineToolsFolder Condition=" '$(CommandLineToolsFolder)' == '' ">7.0</CommandLineToolsFolder>
<CommandLineToolsVersion Condition=" '$(CommandLineToolsVersion)' == '' ">8512546_latest</CommandLineToolsVersion>
<CommandLineToolsBinPath Condition=" '$(CommandLineToolsBinPath)' == '' ">$(AndroidSdkFullPath)\cmdline-tools\$(CommandLineToolsFolder)\bin</CommandLineToolsBinPath>
<!-- Version numbers and PkgVersion are found in https://dl-ssl.google.com/android/repository/repository2-1.xml -->
<EmulatorVersion Condition=" '$(EmulatorVersion)' == '' ">8129060</EmulatorVersion>
<EmulatorPkgRevision Condition=" '$(EmulatorPkgRevision)' == '' ">31.3.1</EmulatorPkgRevision>
<!-- Version numbers and PkgVersion are found in https://dl-ssl.google.com/android/repository/repository2-3.xml -->
<EmulatorVersion Condition=" '$(EmulatorVersion)' == '' ">9364964</EmulatorVersion>
<EmulatorPkgRevision Condition=" '$(EmulatorPkgRevision)' == '' ">32.1.9</EmulatorPkgRevision>
<EmulatorToolPath Condition=" '$(EmulatorToolPath)' == '' ">$(AndroidSdkFullPath)\emulator</EmulatorToolPath>
<EmulatorToolExe Condition=" '$(EmulatorToolExe)' == '' ">emulator</EmulatorToolExe>
<NdkBuildPath Condition=" '$(NdkBuildPath)' == '' And '$(HostOS)' != 'Windows' ">$(AndroidNdkDirectory)\ndk-build</NdkBuildPath>
Expand Down
1 change: 1 addition & 0 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<PropertyGroup>
<TestAvdApiLevel Condition=" '$(TestAvdApiLevel)' == '' ">29</TestAvdApiLevel>
<TestAvdAbi Condition=" '$(TestAvdAbi)' == '' and '$(HostOS)' == 'Darwin' and '$(HostOSArchitecture)' == 'Arm64' ">arm64-v8a</TestAvdAbi>
<TestAvdAbi Condition=" '$(TestAvdAbi)' == '' ">x86_64</TestAvdAbi>
<TestAvdType Condition=" '$(TestAvdType)' == '' ">default</TestAvdType>
<TestDeviceName Condition=" '$(TestDeviceName)' == '' ">pixel_4</TestDeviceName>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;

namespace Xamarin.Android.Prepare
{
Expand Down Expand Up @@ -30,10 +31,14 @@ public AndroidToolchain ()
string XABuildTools30PackagePrefix = Context.Instance.Properties [KnownProperties.XABuildTools30PackagePrefix] ?? String.Empty;
string XAPlatformToolsVersion = GetRequiredProperty (KnownProperties.XAPlatformToolsVersion);
string XAPlatformToolsPackagePrefix = Context.Instance.Properties [KnownProperties.XAPlatformToolsPackagePrefix] ?? String.Empty;
bool isArm64Apple = Context.Instance.OS.Flavor == "macOS" && RuntimeInformation.OSArchitecture == Architecture.Arm64;
string emulatorArch = isArm64Apple ? "aarch64" : "x64";
string systemImageArch = isArm64Apple ? "arm64-v8a" : "x86_64";

// Upstream manifests with version information:
//
// https://dl-ssl.google.com/android/repository/repository2-1.xml
// https://dl-ssl.google.com/android/repository/repository2-3.xml
// * platform APIs
// * build-tools
// * command-line tools
Expand Down Expand Up @@ -87,10 +92,10 @@ public AndroidToolchain ()
dependencyType: AndroidToolchainComponentType.BuildDependency,
buildToolVersion: "47.0.0"
),
new AndroidToolchainComponent ($"x86_64-29_r07-{osTag}",
destDir: Path.Combine ("system-images", "android-29", "default", "x86_64"),
new AndroidToolchainComponent (isArm64Apple ? $"{systemImageArch}-29_r08" : $"{systemImageArch}-29_r08-{osTag}",
destDir: Path.Combine ("system-images", "android-29", "default", systemImageArch),
relativeUrl: new Uri ("sys-img/android/", UriKind.Relative),
pkgRevision: "7",
pkgRevision: "8",
dependencyType: AndroidToolchainComponentType.EmulatorDependency
),
new AndroidToolchainComponent ($"android-ndk-r{AndroidNdkVersion}-{osTag}",
Expand Down Expand Up @@ -123,7 +128,7 @@ public AndroidToolchain ()
buildToolName: "android-sdk-platform-tools",
buildToolVersion: XAPlatformToolsVersion
),
new AndroidToolchainComponent ($"emulator-{osTag}_x64-{EmulatorVersion}",
new AndroidToolchainComponent ($"emulator-{osTag}_{emulatorArch}-{EmulatorVersion}",
destDir: "emulator",
pkgRevision: EmulatorPkgRevision,
dependencyType: AndroidToolchainComponentType.EmulatorDependency
Expand Down

0 comments on commit f04671a

Please sign in to comment.